Gulp 观看整个文件夹并合并保存的文件
Gulp watch entire folder & compile saved file
我想做的就是看:
myprojects/less
此目录中有数百个 Less 文件。保存文件时,我只想编译保存的文件。
以下内容正确但编译了所有 less 文件。有点太多的开销。
gulp.task('compileCurrentTheme', function () {
// is there a way to get the filename that is saved and pass it dynamically to gulp.src?
return gulp.src('less/**/*.less')
.pipe(less())
.pipe(gulp.dest('./css'));
});
gulp.task('watch', function(){
gulp.watch(['less/**/*.less' ], ['compileCurrentTheme']);
});
感谢@CriticalImpact 的建议。虽然我没有接受你的建议,但它让我走上了正确的道路。
var changed = require('gulp-changed');
gulp.task('compileCurrentTheme', function () {
return gulp.src('less/**/*.less')
.pipe(changed('./css', { extension: '.css' }))
.pipe(less())
.pipe(gulp.dest('./css'));
});
gulp.task('watch', function(){
gulp.watch(['less/**/*.less' ], ['compileCurrentTheme']);
});
根据@Justin W Hall 的回答,如果使用 Gulp 4,监视功能的格式为:
gulp.task('watch', function(){
gulp.watch(['less/**/*.less' ], gulp.series('compileCurrentTheme'));
});
我想做的就是看:
myprojects/less
此目录中有数百个 Less 文件。保存文件时,我只想编译保存的文件。
以下内容正确但编译了所有 less 文件。有点太多的开销。
gulp.task('compileCurrentTheme', function () {
// is there a way to get the filename that is saved and pass it dynamically to gulp.src?
return gulp.src('less/**/*.less')
.pipe(less())
.pipe(gulp.dest('./css'));
});
gulp.task('watch', function(){
gulp.watch(['less/**/*.less' ], ['compileCurrentTheme']);
});
感谢@CriticalImpact 的建议。虽然我没有接受你的建议,但它让我走上了正确的道路。
var changed = require('gulp-changed');
gulp.task('compileCurrentTheme', function () {
return gulp.src('less/**/*.less')
.pipe(changed('./css', { extension: '.css' }))
.pipe(less())
.pipe(gulp.dest('./css'));
});
gulp.task('watch', function(){
gulp.watch(['less/**/*.less' ], ['compileCurrentTheme']);
});
根据@Justin W Hall 的回答,如果使用 Gulp 4,监视功能的格式为:
gulp.task('watch', function(){
gulp.watch(['less/**/*.less' ], gulp.series('compileCurrentTheme'));
});