启动项目只执行一次serve任务
修改内容不要再去执行serve,否则会有提示
const { src, dest, series, watch, parallel } = require("gulp");
const del = require("del");
const webserver = require("gulp-webserver");
function clean(cb) {
console.log('清理');
return del("./dist/"); //删除指定的目录,为转存文件做准备
cb()
}
function js(cb) {
console.log('处理js');
src("./src/js/*.js")
.pipe(dest("./dist/js"));
cb();
}
function html(cb) {
console.log('处理html');
src("./src/html/*.html")
.pipe(dest("./dist/html"));
cb();
}
function serve() {
src("./").pipe(
webserver({
host: "localhost",
port: 366,
livereload: true, // 实时重新加载
open: "dist/html/my.html", // 启动时默认浏览器打开的文件
directoryListing: {
enable: true,
path: "./dist/html",
}
})
);
}
const Run = series(
clean,
parallel(js,html)
)
watch(['./src/'], Run);
exports.default = series(Run,serve);