Grunt.js & uglify adds aggregated code to a file instead of rewriting it

I am working on some automation tasks, and I noticed that the grunt.js and uglify modules do not overwrite the mini file. They add a new version of code every time I run grunt tasks.

module.exports = function(grunt) { grunt.initConfig({ uglify : { build : { src : ['**/*.js', '!*.min.js'], cwd : 'js/app/modules/', dest : 'js/app/modules/', expand : true, ext : '.main.min.js', }, } }); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.registerTask('default', ['uglify']); }; 

What can I do to avoid this? I just need a new version of the code in the file.

+4
source share
2 answers

I had the same problem with the following configuration for all files in subfolders: js / (e.g. js / lib / *. Js):

  build: { expand: true, cwd: 'js/', src: ['**/*.js','!*.min.js'], dest: 'js/', ext: '.min.js', } 

You have to limit more files, because if the file matches the src parameter, the content will be added and will not be replaced - since it is "blocked", I think:

  src: ['**/*.js','!**/*.min.js'] 

This should solve your problem.

+10
source

Thanks SpazzMarticus! I am user grunt-newer to run uglify with only newer files. You can try the following:

 grunt.initConfig({ uglify: { options: { }, build: { files: [{ expand: true, cwd: 'public/js', src: ['**/*.js','!**/*.min.js'], dest: 'public/js', ext: '.min.js' }] } }, watch: { options: { livereload: true, nospawn: true }, scripts:{ files: ['public/js/**/*.js'], tasks: ['newer:uglify'] } } }); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-newer'); grunt.registerTask('yt', ['watch']); 
+1
source

All Articles