It's easy to complier JS that is changed after setting gunt-contrib-watch.
But how to watch multiple files but compile only Changed ?
But how to watch multiple files but compile only Changed ?
This is a sample [Grunt watch] & [ Google closure] for you :
*Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
closure-compiler: {
other: {
closurePath:'/Library/closure/',
js: ['js/*.js'
],
jsOutputFile: 'js/dist/*.js',
noreport: true,
options: {
compilation_level: 'SIMPLE_OPTIMIZATIONS',
//compilation_level: 'ADVANCED_OPTIMIZATIONS',
warning_level:"DEFAULT",
define: [
'"DEBUG=false"',
'"UI_DELAY=500"'
],
}
}
},
watch: {
other: {
files: ['js/*.js'],
tasks: ['closure-compiler:other'],
options: {
debounceDelay: 500,
spawn: false,
},
}
}
});
grunt.loadNpmTasks('grunt-closure-compiler');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.event.on('watch', function(action, filepath, target) {
//change the source and destination in the uglify task at run time so that it affects the changed file only
var destFilePath = filepath.replace(/^js\/(.+)\.js$/, 'js/dist/$1.min.js');
grunt.log.write(destFilePath);
grunt.config('closure-compiler.other.js', filepath);
grunt.config('closure-compiler.other.jsOutputFile', destFilePath);
});
};
留言
張貼留言