Gulp 从未定义的任务:未定义的

lh80um4z  于 2022-12-08  发布在  Gulp
关注(0)|答案(1)|浏览(270)

I used a similar configuration to another project (with more tasks) but I'm not sure what I'm missing here to get this error:

AssertionError [ERR_ASSERTION]: Task never defined: undefined

So would like to use Gulp 4 and use 3 tasks (build HTML, minify JavaScript, and create a server). I'm dividing it into 2 processes: dev and build.

const gulp        = require('gulp');
const jsmin       = require('gulp-jsmin');
const browserSync = require('browser-sync').create();

function jsMinify () {
  return gulp.src('./src/**/*.js')
    .pipe(jsmin())
    .pipe(gulp.dest('./dist'))
}

function buildHTML () {
  return gulp.src('./src/html/**/*.html')
    .pipe(gulp.dest('./dist'))
}

function buildServe () {
  browserSync.init({
    server: {
        baseDir: "./dist/",
    },
    port: 9001
  });
}

function watch (){
  browserSync.init({
    server: {
        baseDir: "./src/",
    },
    port: 8080
  });
  gulp.watch('./src/**/*.html').on('change', browserSync.reload);
  gulp.watch('./src/**/*.js').on('change', browserSync.reload);
};

const dev = gulp.series(watch);
const build = gulp.series(
  gulp.parallel(buildHTML, jsMinify),
  buildServe()
);

exports.dev = dev;
exports.build = build;

Am I missing something about Gulp 4 or this code should run without any issue?

ar7v8xwq

ar7v8xwq1#

这是一个错误:

const build = gulp.series(
      gulp.parallel(buildHTML, jsMinify),
      buildServe()    // <= error here, don't call the function just list it like below
    );

    const build = gulp.series(
      gulp.parallel(buildHTML, jsMinify),
      buildServe     //  <= removed ()
    );

gulp.series()参数是函数名或任务名。通过使用buildServe(),我认为它返回的是undefined,因此您的错误消息undefined从未被定义为任务。我希望这是有意义的。
[我还无法测试此更改以查看它是否修复了您的问题,但我在您的代码中没有看到任何其他问题。]

相关问题