How to clean a project correctly with gulp?

后端 未结 6 1698
悲哀的现实
悲哀的现实 2020-12-25 10:45

On the gulp page there is the following example:

gulp.task(\'clean\', function(cb) {
  // You can use multiple globbing patterns as you would with `gulp.src`         


        
6条回答
  •  醉话见心
    2020-12-25 10:55

    You can make separate tasks to be triggered by watch:

    gulp.task('clean', function(cb) {
      // You can use multiple globbing patterns as you would with `gulp.src`
      del(['build'], cb);
    });
    
    var scripts = function() {
      // Minify and copy all JavaScript (except vendor scripts)
      return gulp.src(paths.scripts)
        .pipe(coffee())
        .pipe(uglify())
        .pipe(concat('all.min.js'))
        .pipe(gulp.dest('build/js'));
    };
    gulp.task('scripts', ['clean'], scripts);
    gulp.task('scripts-watch', scripts);
    
    // Copy all static images
    var images = function() {
     return gulp.src(paths.images)
        // Pass in options to the task
        .pipe(imagemin({optimizationLevel: 5}))
        .pipe(gulp.dest('build/img'));
    };
    gulp.task('images', ['clean'], images);
    gulp.task('images-watch', images);
    
    // the task when a file changes
    gulp.task('watch', function() {
      gulp.watch(paths.scripts, ['scripts-watch']);
      gulp.watch(paths.images, ['images-watch']);
    });
    
    // The default task (called when you run `gulp` from cli)
    gulp.task('default', ['watch', 'scripts', 'images']);
    

提交回复
热议问题