I need to change configuration of my uglify task for only minify file as needed (as explained here for the jshint task : https://github.com/gruntjs/grunt-contrib-watch#compiling-files-as-needed)
The modification works well for the jshint task but not for uglify, i think the problem is the property path...
Any help would be appreciated ;)
Here is my Gruntfile.js :
module.exports = function (grunt) {
grunt.initConfig({
// define source files and their destinations
jshint: {
all: ['dev/**/*.js'],
},
uglify: {
dynamic_mappings: {
// Grunt will search for "**/*.js" under "dev/" when the "minify" task
// runs and build the appropriate src-dest file mappings then, so you
// don't need to update the Gruntfile when files are added or removed.
files: [{
expand: true, // Enable dynamic expansion.
cwd: 'dev/', // Src matches are relative to this path.
src: ['**/*.js'], // Actual pattern(s) to match.
dest: 'build', // Destination path prefix.
ext: '.min.js', // Dest filepaths will have this extension.
},
],
}
}
watch: {
options: { spawn: false },
js: { files: 'dev/**/*.js', tasks: [ 'uglify' ] },
}
});
// load plugins
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
// default task
grunt.registerTask('default', [ 'watch' ]);
grunt.event.on('watch', function(action, filepath) {
grunt.config(['jshint', 'all'], filepath);
grunt.config('uglify.dynamic_mappings.files', [{src: filepath }]);
});
};
The line
grunt.config('uglify.dynamic_mappings.files', [{src: filepath }]);
Is completely replacing the original configuration for uglify.dynamic_mappings.files
Instead try including the other original parameters along with the new src: filepath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With