Gulp 4:“您是否忘记在监视任务中发信号通知异步完成”

时间:2019-02-07 21:41:16

标签: gulp gulp-watch gulp-4

在我的Gulpfile中,我遇到一个问题,那就是控制台中总是会出现错误:

[22:33:32] The following tasks did not complete: default, watch, watch:views, watch:styles, watch:scripts
[22:33:32] Did you forget to signal async completion?

但是,据我所知,我只是定义了一些监视任务,对此没有任何怀疑。那么,gulp watch任务的错误在哪里?

gulp.task('reload', (done) => {
 browserSync.reload();

 done();
});

gulp.task('watch:views', () => {
 gulp.watch(getPath(paths.views.watch), gulp.series('lint', gulp.parallel('views', 'assets'), 'reload'));
});

gulp.task('watch:styles', () => {
 gulp.watch(getPath(paths.styles.all), gulp.series('lint', gulp.parallel('styles', 'assets'), 'reload'));
});

gulp.task('watch:scripts', () => {
 gulp.watch(getPath(paths.scripts.all), gulp.series('scripts', 'reload'));
});

gulp.task('watch', gulp.parallel('watch:views', 'watch:styles', 'watch:scripts'));

gulp.task('default', gulp.series(
 'clean',
 'lint',
 gulp.parallel(['views', 'styles', 'scripts', 'assets']),
 'serve',
 'watch',
));

已更新:资产,样式和脚本任务。

这些任务被定义为其他文件中的导出默认功能。在gulpfile中,它们将被加载并设置为任务。单独调用这些任务没有问题,它们将正确完成异步完成的信号。并且默认任务(包括所有这些任务)运行良好。只是当监视任务开始时它就会失败。

gulp.assets.js

import gulp from 'gulp';

import { paths, getPath, getTargetPath } from './paths';

export default () => {
  return gulp.src(getPath(paths.copy.src), {
    base: getPath(paths.copy.base)
  })
    .pipe(gulp.dest(getTargetPath(paths.target.assets)));
}

gulp.styles.js

import gulp from 'gulp';
import sass from 'gulp-sass';
import rename from 'gulp-rename';
import cleanCSS from 'gulp-clean-css';
import gulpif from 'gulp-if';

import { paths, getPath, getTargetPath } from './paths';
import { isProd } from './env';

export default () => {
  return gulp
    .src(getPath(paths.styles.main))
    .pipe(sass().on('error', sass.logError))
    .pipe(gulpif(isProd(), cleanCSS()))
    .pipe(rename({ dirname: '' }))
    .pipe(gulp.dest(getTargetPath(paths.target.assets)));
};

gulp.scripts.js

import gulp from 'gulp';
import browserify from 'browserify';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import babelify from 'babelify';
import rename from 'gulp-rename';
import gulpif from 'gulp-if';
import uglify from 'gulp-uglify-es';

import { paths, getPath, getTargetPath } from './paths';
import { isProd } from './env';

export default () => {
  return browserify({
    entries: getPath(paths.scripts.main),
    debug: true,
    extensions: ['.js', '.jsx']
  })
  .transform(babelify.configure({
    presets: ["@babel/preset-env", "@babel/preset-react"]
  }))
  .bundle()
  .pipe(source('main.js'))
  .pipe(buffer())
  .pipe(gulpif(isProd(), uglify()))
  .pipe(rename({ dirname: '' }))
  .pipe(gulp.dest(getTargetPath(paths.target.assets)));
}

0 个答案:

没有答案