【问题标题】:Moving files from node_modules to wwwroot with gulp in VS2015 asp.net core 1.0 project在 VS2015 asp.net core 1.0 项目中使用 gulp 将文件从 node_modules 移动到 wwwroot
【发布时间】:2016-08-07 15:24:19
【问题描述】:

当我创建一个新的 ASP.NET Core 1.0 应用程序时,我想使用 npm 而不是 bower。所以我删除了 bower.json 并另外删除了预装在 wwwroot/lib 文件夹中的所有内容。

我将一个 package.json 文件添加到我的解决方案中,其中包含以下开发依赖项:

"devDependencies": {
    "bootstrap": "3.3.7",
    "jquery": "3.1.0",
    "jquery-validation": "1.15.1",
    "jquery-validation-unobtrusive": "3.2.6"
}

但是,NPM 将所有库下载到我项目根目录中的 node_modules 文件夹中。

我相信这就是 Gulp 的用途。有人可以告诉我如何使用 gulp 将分发文件从 node_modules 发送到我的 wwwroot 目录。如果有任何我找不到的教程,请链接。

【问题讨论】:

标签: node.js visual-studio-2015 npm gulp asp.net-core-1.0


【解决方案1】:

阅读这篇文章https://wildermuth.com/2017/11/19/ASP-NET-Core-2-0-and-the-End-of-Bower 当我看到 netcore 2.0 中对 bower 的支持不好时,我使用了这个

为 bower.json 中的每个包执行 npm install xyzyarn install xyz。更新 gulp 以将内容从 node_modules 复制到 lib。在*.csproj 文件中将bower install 替换为npm installyarn install

总结 gulpfile:

var merge = require('merge-stream');

// Old bower behavior would be "*" in before and "" in after but you don't want that much.
var webpackages = {
    "requirejs": {"bin/*": "bin/" }
    // ...
}

gulp.task("dist_lib", function() {
    var streams=[];
    for (var package in webpackages)
       for (var item in webpackages[package])
           streams.push(gulp.src("node_modules/" + package + "/" + item)
               .pipe(gulp.dest("lib/" + package + "/" + webpackage[package][item])));
}

【讨论】:

  • 是我还是merge不习惯?
猜你喜欢
  • 1970-01-01
  • 2016-07-17
  • 2016-06-02
  • 1970-01-01
  • 1970-01-01
  • 2015-10-18
  • 1970-01-01
  • 2016-11-01
  • 1970-01-01
相关资源
最近更新 更多