简体   繁体   中英

Gulp : wait before executing next instruction

It seems that Gulp execute all instructions synchronously. Because of that, I can't concat JS files first then, after, delete the JS folder.

Here is my code :

gulp.task('build', function() {

    // Concat JS files
    gulp.src([
        "www/js/navigation.js",
        "www/js/initialization.js"
    ])
        .pipe(concat('min.js'))
        .pipe(gulp.dest('www'))

    // Delete JS Folder
    del([
        'www/js/',
    ]);
});

When executed, I get the error :

> $ gulp build 
> [12:18:27] Using gulpfile ~/project/gulpfile.js
> [12:18:27] Starting 'build'... [12:18:27] Finished 'build' after 13 ms
> 
> events.js:72
>         throw er; // Unhandled 'error' event
>               ^ Error: ENOENT, open '/Users/lepix/project/www/js/initialization.js'

You should separate the tasks and call del.sync:

gulp.task('reset', function () {
    return del.sync([
        'www/js/'
    ]);
});

gulp.task('minify', function(){
    gulp.src([
        "www/js/navigation.js",
        "www/js/initialization.js"
    ])
        .pipe(concat('min.js'))
        .pipe(gulp.dest('www'))
})

gulp.task('build', ['reset', 'minify']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM