Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt.js & uglify is appending uglified code to file instead of rewriting it

I'm working on some automation tasks and I noticed that grunt.js and uglify module are not rewriting the minified file. They're appending a new version of code everytime I start 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 it? I just want the newest version of code in the file.

like image 683
sunpietro Avatar asked Dec 19 '22 23:12

sunpietro


1 Answers

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

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

You have to restrict more files, because if a file matches the src-option the content will be appended and not replaced - because it is "locked" i guess:

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

That should fix your problem.

like image 124
SpazzMarticus Avatar answered Jan 13 '23 13:01

SpazzMarticus