Npm 如何从3迁移到gulp v4?
我想在对文件进行任何更改时运行名为“html”的任务。它在gulp的前一个版本中工作,现在它生成以下错误。 gulp.start不是一个函数 我找不到任何方法在新版的gulp中实现这一点。我发现我需要改变它的功能,但我似乎找不到我需要改变什么以及如何改变 代码的其余部分如下所示Npm 如何从3迁移到gulp v4?,npm,gulp,Npm,Gulp,我想在对文件进行任何更改时运行名为“html”的任务。它在gulp的前一个版本中工作,现在它生成以下错误。 gulp.start不是一个函数 我找不到任何方法在新版的gulp中实现这一点。我发现我需要改变它的功能,但我似乎找不到我需要改变什么以及如何改变 代码的其余部分如下所示 gulp.watch('watch', function() { watch('./app/index.html', function() { gulp.start('html'); }); }); 您不需要将
gulp.watch('watch', function() {
watch('./app/index.html', function() {
gulp.start('html');
});
});
您不需要将任务转换为命名函数——尽管这被认为是最佳实践,而且很容易做到 要修复手表任务,请尝试:
var gulp = require("gulp"),
watch = require('gulp-watch');
gulp.task('default', function(done){
console.log("You created the default task");
done();``
});
gulp.task('html', function(done){
console.log('modifying the html');
done();
});
gulp.watch('watch', function() {
watch('./app/index.html', function() {
gulp.start('html');
});
});
要更改为命名函数,请执行以下操作:
gulp.watch('watch', function(done) {
watch('./app/index.html', gulp.series('html'));
done();
});
请注意,现在,watch
任务不是作为字符串调用的,即,'watch'
,而只是watch
在exports.html
中,并不严格需要gulp.series
,因为那里只有一个任务,所以exports.html=html代码>已足够
如果希望直接调用任务,则只需导出任务(例如从命令行gulp html
)。如果说html
任务将仅由其他任务在内部调用,则无需导出它。谢谢,请注意,这不是我所期望的,但我目前似乎无法描述问题。当我写更多的任务并在代码中添加一些功能时,我会给你回复的。
function html(done) {
gulp.src(….)
console.log('modifying the html');
done();
};
function watch(done) {
watch('./app/index.html', gulp.series('html'));
done();
});
exports.html= gulp.series(html);
exports.default = gulp.series(watch);