gruntjs - Change the configuration of the task uglify dynamically -
i need change configuration of uglify task minify file needed (as explained here jshint task : https://github.com/gruntjs/grunt-contrib-watch#compiling-files-as-needed)
the modification works jshint task not uglify, think problem property path...
any appreciated ;)
here gruntfile.js :
module.exports = function (grunt) { grunt.initconfig({ // define source files , destinations jshint: { all: ['dev/**/*.js'], }, uglify: { dynamic_mappings: { // grunt search "**/*.js" under "dev/" when "minify" task // runs , build appropriate src-dest file mappings then, // don't need update gruntfile when files added or removed. files: [{ expand: true, // enable dynamic expansion. cwd: 'dev/', // src matches relative path. src: ['**/*.js'], // actual pattern(s) match. dest: 'build', // destination path prefix. ext: '.min.js', // dest filepaths have 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 replacing original configuration uglify.dynamic_mappings.files
instead try including other original parameters along new src: filepath
Comments
Post a Comment