[英]Browser-sync, scripts and styles reload not working when migrating from gulp 3.x to gulp 4.x
I am trying to upgrade gulp from 3.x to 4.x When using gulp watch, the styles, scripts and inject function works well.But when I make any file changes the scripts and styles need to be loaded automatically. 这是行不通的。
我尝试将 gulp.series 添加到每个 function。
function isOnlyChange(event) {
return event.type === 'changed';
}
gulp.watch([
path.join(conf.paths.src, '/app/**/*.css'),
path.join(conf.paths.src, '/app/**/*.scss')
], gulp.series(function (event) {
if (isOnlyChange(event)) {
gulp.series('styles-reload');
} else {
gulp.series('inject-reload');
}
}));
当我在 styles 文件中进行更改时,Gulp 手表需要重新加载 styles 但这没有执行。 有人可以帮助我如何在 gulp 4.x 中执行
你可以尝试这样的事情:
function myWatch() {
gulp.watch(['./scss/*.scss'], { events: 'change' }, function (cb) {
console.log("here 1");
// gulp.series('styles-reload');
cb();
});
gulp.watch(['./scss/*.scss'], { events: ['add', 'addDir', 'unlink', 'unlinkDir', 'ready', 'error'] }, function (cb) {
console.log("here 2");
// gulp.series('inject-reload');
cb();
});
}
请参阅https://gulpjs.com/docs/en/api/watch#options以查看您可以包含在第二个gulp.watch
中的事件的描述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.