是否有顺序执行watcher.on
进程和其他监视任务的方法?
[我使用on
的chokidar实例的gulp.watch
方法仅获得已编辑文件的名称。
function sass_compile(path) {
return src("./style/**/*.scss")
.on("end", () => {
console.log("completed" + path + "!");
})
.pipe(sass())
.pipe(dest("css"))
}
function reload(done) {
browserSync.reload();
done();
}
exports.default = function () {
browserSync.init();
watch("./style/**/*.scss").on("change", (path) => {
sass_compile(path);
console.log("completed?");
});
watch(["./style/**/*.scss", "./js/**/*.js", "./tests/**/**/*.spec.js"], reload);
};
如果您在这种状态下编辑scss文件,则日志将在终端中显示为这样。这表明重新加载可能在SCSS编译完成之前开始。
[Browsersync] Serving files from: ./
completed?
[03:18:58] Starting 'reload'...
[03:18:58] Finished 'reload' after 1.3 ms
completedsass\_variables.scss!
[Browsersync] Reloading Browsers...
由于这种情况不安全,我希望上述日志输出将得到如下改进:
[Browsersync] Serving files from: ./
completed?
completedsass\_variables.scss!
[03:18:58] Starting 'reload'...
[03:18:58] Finished 'reload' after 1.3 ms
[Browsersync] Reloading Browsers...
此问题使我感到困惑,因为一个任务使用chokidar实例。如何实现?
我的package.json看起来像这样:
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.26.7",
"gulp": "^4.0.2",
"gulp-sass": "^4.0.2",
}
}