I have a gulpfile that needs to clear my dist directory before the code changes. Sometimes a clean task still works while the code is minimized, which leads to some missing files.
What makes it do it? My understanding is that dependencies for a task will be completed before , if the task is running, and the dependency will be executed only once, even if it is a dependency for several tasks.
var gulp = require('gulp'); var gulpLoadPlugins = require('gulp-load-plugins'); var plugins = gulpLoadPlugins(); var del = require('del'); gulp.task('default', ['css', 'js', 'fonts']); gulp.task('clean', function(cb) { del(['dist/**'], cb); }); gulp.task('css', ['clean'], function() { return gulp.src('style.css') .pipe(plugins.autoprefixer({ browsers: ['last 2 versions'] })) .pipe(gulp.dest('dist')) .pipe(plugins.minifyCss({ noRebase: true, keepSpecialComments: 0 })) .pipe(plugins.rename({extname: '.min.css'})) .pipe(gulp.dest('dist')); }); gulp.task('js', ['clean'], function() { return gulp.src('scripts.js') .pipe(gulp.dest('dist')) .pipe(plugins.uglify({preserveComments: 'some'})) .pipe(plugins.rename({extname: '.min.js'})) .pipe(gulp.dest('dist')); }); gulp.task('fonts', ['clean'], function() { return gulp.src('fonts/*') .pipe(gulp.dest('dist/fonts')); });
UPDATE: Gulp concludes that the clean task runs before the rest, but sometimes not all output files are in the dist directory. Sometimes they are.
[09:47:15] Using gulpfile /Users/raddevon/Documents/projects/AlphaBlog/theme/gulpfile.js [09:47:15] Starting 'clean'... [09:47:15] Finished 'clean' after 8.06 ms [09:47:15] Starting 'css'... [09:47:15] Starting 'js'... [09:47:16] Starting 'fonts'... [09:47:16] Finished 'js' after 399 ms [09:47:16] Finished 'css' after 899 ms [09:47:16] Finished 'fonts' after 267 ms [09:47:16] Starting 'default'... [09:47:16] Finished 'default' after 7.78 μs
javascript gulp
raddevon
source share