2015-02-16 6 views
12

Sono nuovo di Gulp e hanno i seguenti GulpfileGet Gulp guardare per eseguire la funzione solo su modificata del file

var gulp = require('gulp'); 
var jshint = require('gulp-jshint'); 
var concat = require('gulp-concat'); 
var rename = require('gulp-rename'); 
var uglify = require('gulp-uglify'); 

gulp.task('compress', function() { 
    return gulp.src('js/*.js') // read all of the files that are in js with a .js extension 
     .pipe(uglify()) // run uglify (for minification) 
     .pipe(gulp.dest('dist/js')); // write to the dist/js file 
}); 

// default gulp task 
gulp.task('default', function() { 

    // watch for JS changes 
    gulp.watch('js/*.js', function() { 
     gulp.run('compress'); 
    }); 

}); 

Vorrei configurare questo per rinominare, minify e salvare solo il mio file modificato nella cartella dist . Qual è il modo migliore per farlo?

+0

possibile duplicato di [Come faccio a guardare i file più diffusi con gulp-browserify ma ne elabora solo uno?] (Http://stackoverflow.com/questions/21818188/how-do-i-watch-mutliple-files-with- gulp-browserify-but-process-only-one) – kamituel

risposta

10

Ecco come:

// Watch for file updates 
gulp.task('watch', function() { 
    livereload.listen(); 

    // Javascript change + prints log in console 
    gulp.watch('js/*.js').on('change', function(file) { 
     livereload.changed(file.path); 
     gutil.log(gutil.colors.yellow('JS changed' + ' (' + file.path + ')')); 
    }); 

    // SASS/CSS change + prints log in console 
    // On SASS change, call and run task 'sass' 
    gulp.watch('sass/*.scss', ['sass']).on('change', function(file) { 
     livereload.changed(file.path); 
     gutil.log(gutil.colors.yellow('CSS changed' + ' (' + file.path + ')')); 
    }); 

}); 

anche grandi da usare gulp-livereload con essa, è necessario installare il Chrome plugin per farlo funzionare btw.

+0

Esiste un modo per rispettare il glob? 'file.path' restituisce il percorso assoluto così' ** 'non sono rispettati quando si tratta di' gulp.dest() '. – Markus

+1

@Markus. guarda 'gulp-changed' – user1167442

Problemi correlati