I am using google-closure-compiler and gulp to minify my angularjs files.
Here is my gulpfile code;
var closureCompiler = require('google-closure-compiler').gulp();
var flatmap = require('gulp-flatmap');
var path = require('path');
gulp.task('js-closure', function () {
return gulp.src(['app/js/*.js', 'dist/single.js'], {base: './'})
.pipe(flatmap(function(stream, file) {
return stream.pipe(closureCompiler({
compilation_level: 'SIMPLE_OPTIMIZATIONS',
warning_level: 'QUIET',
language_in: 'ECMASCRIPT6_STRICT',
language_out: 'ECMASCRIPT5_STRICT',
output_wrapper: '(function(){\n%output%\n}).call(this)',
js_output_file: path.basename(file.path).replace(/js$/, 'min.js')
}))
}))
.pipe(gulp.dest('./dist/js'));
});
The code works fine. However, I have to run gulp js-closure
manually on the command-line to compile the js files.
I would like to compile the js files automatically whenever any one of the js files are changed.
EDIT: gulp-watch seems to be a good fit for this problem https://www.npmjs.com/package/gulp-watch. How can the code be modified to use gulp-watch? Any good sample examples?