gulp 在 .net 核心中加载 bootstrap / jquery
gulp to load bootstrap / jquery in .net core
试图将我的 .net 核心 jquery、bootstrap 等从静态文件移动到由 package.json / npm 更新。看起来我需要 gulp 或 grunt 来完成这项工作。但我无法从堆栈或其他可行的地方找到任何示例。任何人都可以举一个例子或网站吗?
解决方案 1(推荐)
让您的 move/migration 尽可能轻松和无痛的最佳方法是使用 Libman for Asp.Net Core,这是一种简单易用的脑死亡。
它只需要您指定所需库的名称和输出文件夹,同时允许您挑选要复制的文件而不是整个库。
这种方法的好处是它具有 vs 集成,并在您键入时提供智能感知。
解决方案 2
编写一个 gulp 任务,将您需要的文件从 npm 文件夹移动到 wwwroot 文件夹。
假设您已经安装了 gulp 文件,请安装一个名为 gulp-rename
的附加模块
npm i gulp-rename --save-dev
示例:
var rename = require('gulp-rename');
var staticFiles = [
'./node_modules/jQuery/dist/**/*.js',
'./node_modules/bootstrap/dist/**/*.{js,css}'
];
gulp.task('npmModules', function(){
// the base option sets the relative root for the set of files,
// preserving the folder structure
return gulp.src(staticFiles, { base: './' })
.pipe(rename(path => path.dirname = path.dirname.replace('node_modules', '')))
.pipe(gulp.dest('wwwroot/dist/'));
});
试图将我的 .net 核心 jquery、bootstrap 等从静态文件移动到由 package.json / npm 更新。看起来我需要 gulp 或 grunt 来完成这项工作。但我无法从堆栈或其他可行的地方找到任何示例。任何人都可以举一个例子或网站吗?
解决方案 1(推荐)
让您的 move/migration 尽可能轻松和无痛的最佳方法是使用 Libman for Asp.Net Core,这是一种简单易用的脑死亡。
它只需要您指定所需库的名称和输出文件夹,同时允许您挑选要复制的文件而不是整个库。
这种方法的好处是它具有 vs 集成,并在您键入时提供智能感知。
解决方案 2
编写一个 gulp 任务,将您需要的文件从 npm 文件夹移动到 wwwroot 文件夹。
假设您已经安装了 gulp 文件,请安装一个名为 gulp-rename
的附加模块npm i gulp-rename --save-dev
示例:
var rename = require('gulp-rename');
var staticFiles = [
'./node_modules/jQuery/dist/**/*.js',
'./node_modules/bootstrap/dist/**/*.{js,css}'
];
gulp.task('npmModules', function(){
// the base option sets the relative root for the set of files,
// preserving the folder structure
return gulp.src(staticFiles, { base: './' })
.pipe(rename(path => path.dirname = path.dirname.replace('node_modules', '')))
.pipe(gulp.dest('wwwroot/dist/'));
});