【问题标题】:gulp4: Did you forget to signal async completion?gulp4:你忘记发出异步完成信号了吗?
【发布时间】:2019-08-17 04:53:22
【问题描述】:

从 gulp3 迁移到 4 时遇到一些问题。我看过各种帖子,但似乎仍然无法绕过错误

[12:17:41] 以下任务未完成:服务构建、构建、 [12:17:41] 你忘记发出异步完成信号了吗?

已经尝试在 function(done){.... done();} 中添加异步函数() 和 promise/return

似乎无法进入正确的位置。它似乎停止并构建了我的 lib 和 app .js 文件,但它们缺少一些东西.. 特别是 tinymce 插件..

gulp.task('clean-styles', function(done) {
    var files = [].concat(
        config.temp + '**/*.css',
        config.build + 'styles/**/*.css'
    );
    clean(files, done);
    });

gulp.task('styles', gulp.series('clean-styles', function() {
    log('Compiling Less --> CSS');

    return gulp
        .src(config.less)
        .pipe($.plumber()) // exit gracefully if something fails after this
        .pipe($.less())
    //        .on('error', errorLogger) // more verbose and dupe output. 
    requires emit.
        .pipe($.autoprefixer({browsers: ['last 2 version', '> 5%']}))
        .pipe(gulp.dest(config.temp));
}));

/**
 * Remove all fonts from the build folder
 * @param  {Function} done - callback when complete
 */
gulp.task('clean-fonts', function(done) {
    clean(config.build + 'fonts/**/*.*', done);
});



/**
 * Copy TinyMCE fonts
 * @return {Stream}
 */
gulp.task('fonts-tinymce', function () {
    log('Copying tinymce fonts');

    return gulp
        .src(config.fontsTinyMCE)
        .pipe(gulp.dest(config.build + 'styles/fonts'));
});


/**
 * Copy fonts
 * @return {Stream}
 */
gulp.task('fonts', gulp.series('clean-fonts', 'fonts-bootstrap', 'fonts-tinymce', function () {
    log('Copying fonts');

    return gulp
        .src(config.fonts)
        .pipe(gulp.dest(config.build + 'fonts'));
}));

/**
 * Remove all images from the build folder
 * @param  {Function} done - callback when complete
 */
gulp.task('clean-images', function(done) {
    clean(config.build + 'images/**/*.*', done);
});

/**
 * Compress images
 * @return {Stream}
 */
gulp.task('images', gulp.series('clean-images', function() {
    log('Compressing and copying images');

    return gulp
        .src(config.images)
        .pipe($.imagemin({optimizationLevel: 4}))
        .pipe(gulp.dest(config.build + 'images'));
}));

gulp.task('less-watcher', function() {
    gulp.watch([ config.less ], gulp.series('styles'));
});



/**
 * Optimize all files, move to a build folder,
 * and inject them into the new index.html
 * @return {Stream}
 */
gulp.task('optimize', gulp.series('inject', 'test', function() {
    log('Optimizing the js, css, and html');

    var assets = $.useref.assets({searchPath: './'});
    // Filters are named for the gulp-useref path
    var cssFilter = $.filter('**/*.css');
    var jsAppFilter = $.filter('**/' + config.optimized.app);
    var jslibFilter = $.filter('**/' + config.optimized.lib);

    var templateCache = config.temp + config.templateCache.file;

    return gulp
        .src(config.index)
        .pipe($.plumber())
        .pipe(inject(templateCache, 'templates'))
        .pipe(assets) // Gather all assets from the html with useref
        // Get the css
        .pipe(cssFilter)
        .pipe($.minifyCss())
        .pipe(cssFilter.restore())
        // Get the custom javascript
        .pipe(jsAppFilter)
        .pipe($.ngAnnotate({add: true}))
        .pipe($.uglify())
        .pipe(getHeader())
        .pipe(jsAppFilter.restore())
        // Get the vendor javascript
        .pipe(jslibFilter)
        .pipe($.uglify()) // another option is to override wiredep to use min files
        .pipe(jslibFilter.restore())
        // Take inventory of the file names for future rev numbers
        .pipe($.rev())
        // Apply the concat and file replacement with useref
        .pipe(assets.restore())
        .pipe($.useref())
        // Replace the file names in the html with rev numbers
        .pipe($.revReplace())
        .pipe(gulp.dest(config.build));
}));



/**
 * Build everything
 * This is separate so we can run tests on
 * optimize before handling image or fonts
 */
gulp.task('build', gulp.series('optimize', 'images', 'fonts', function() {
    log('Building everything');

    var msg = {
        title: 'gulp build',
        subtitle: 'Deployed to the build folder',
        message: 'Running `gulp serve-build`'
    };
    del(config.temp);
    log(msg);
    notify(msg);
}));


/**
 * Remove all tinymce fonts from the build folder
 * @param  {Function} done - callback when complete
 */
gulp.task('clean-fonts-tinymce', function (done) {
    clean(config.build + 'styles/fonts/*.*', done);
});



/**
 * serve the build environment
 * --debug-brk or --debug
 * --nosync
 */
gulp.task('serve-build', gulp.series('build', function() {
    serve(false /*isDev*/);
}));

【问题讨论】:

    标签: asynchronous promise gulp


    【解决方案1】:

    我有一些类似的设置,这应该有助于解决错误:

    /**
     * serve the build environment
     * --debug-brk or --debug
     * --nosync
     */
    gulp.task('serve-build', gulp.series('build', function(done) {
        serve(false /*isDev*/);
        done();
    }));
    

    更多关于异步完成的信息可以在the documentation找到

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多