gulp4:您忘记信号异步完成了吗?

时间:2019-08-16 16:34:34

标签: asynchronous promise gulp

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

[12:17:41]以下任务未完成:serve-build,build, [12:17:41]您是否忘记了异步完成信号?

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

似乎找不到正确的位置。似乎停止并构建了我的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*/);
}));

1 个答案:

答案 0 :(得分:0)

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

if (a) object[aa[i - 1]] += "," + a;

有关异步完成的更多信息,请参见the documentation