Changing uglify task configuration dynamically

I need to change the configuration of my uglify task only for the minimum file (as described 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 in the properties 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 }]); }); }; 
+7
gruntjs
source share
2 answers

Line

 grunt.config('uglify.dynamic_mappings.files', [{src: filepath }]); 

Completely replaces the original configuration for uglify.dynamic_mappings.files

Instead, try including other source options along with the new src: filepath

+8
source share

How not to guess already a miniature on each "grunt assembly" in yomanka

  uglify: { onlyScripts: { files: [{ dest: '<%= yeoman.dist %>/scripts/scripts.js', src: ['.tmp/concat/scripts/scripts.js'] }] } } 

In addition, now uglify will not copy your vendor.js from a temporary folder, so add the "vendorJS" section to "copy" the task:

 copy: //... vendorJS: { expand: true, cwd: '.tmp/concat/scripts/', dest: '<%= yeoman.dist %>/scripts/', src: 'vendor.js' } 

Then, in the "build" task, set the uglify parameter to "onlyScripts" and copy the vendor.js file:

  grunt.registerTask('build', [ 'jshint', 'clean:dist', //'wiredep', // ... 'useminPrepare', //'concurrent:dist', 'autoprefixer', 'concat', 'ngAnnotate', 'copy:dist', 'cssmin', 'uglify:onlyScripts', 'copy:vendorJS', // ... ]); 

http://eugenioz.blogspot.in/2014/08/how-to-not-minify-already-minified-on.html

0
source share

All Articles