此答案建议使用 GULP which seems dated now。
您不应该像 html 或 cshtml 文件那样从前端访问 node_modules 文件。所以你是对的,你应该将它们复制到wwwroot 文件夹。
您可以使用Tseng comment 中链接的grunt,但我个人更喜欢Gulp,我认为它更快更容易使用。
您的package.json 文件:
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {
"gulp": "3.9.1",
"gulp-cached": "1.1.0",
}
}
然后在项目的根级别创建gulpfile.js,您可以编写类似的内容
var gulp = require('gulp'),
cache = require('gulp-cached'); //If cached version identical to current file then it doesn't pass it downstream so this file won't be copied
gulp.task('default', 'copy-node_modules');
gulp.task('copy-node_modules', function () {
try {
gulp.src('node_modules/**')
.pipe(cache('node_modules'))
.pipe(gulp.dest('wwwroot/node_modules'));
}
catch (e) {
return -1;
}
return 0;
});
最后打开Task Runner Explorer(如果您使用的是Visual Studio)并执行您的default 任务或直接执行copy-node_modules 任务。
Gulp 非常有用,我建议您探索其他不同的 gulp 任务。您可以合并和缩小 CSS 和 JS 文件,删除 cmets,甚至可以创建 watch 任务,在文件更改后立即执行其他任务。