首页 > 解决方案 > gulpfile.js 4 无限循环

问题描述

我正在使用 gulp 版本 4,我遇到了 javascript 任务的无限循环问题。我真的不明白是什么导致了循环。

// JS
function javascript() {
  return gulp
      .src([paths.js, paths.excludeJS.minJs, paths.excludeJS.underscored], {base: "./"})
      .pipe(plumber({errorHandler: onError}))
      .pipe(include({
        includePaths: [paths.source]
      }))
      .pipe(babel())
      .pipe(ignore.include(paths.excludeJS.underscored))
      .pipe(rename(function (path) {
        path.basename += ".min";
        path.extname = ".js";
      }))
      .pipe(gulp.dest("./"));
}

exports.default = watch;
exports.js = javascript;

标签: javascriptgulpgulp-watch

解决方案


通过添加到监视功能忽略的路径来解决

function watch(){
    gulp.watch(paths.sass, style);
    gulp.watch([paths.js, paths.excludeJS.minJs, paths.excludeJS.underscored], javascript);
}


推荐阅读