Search code examples
gruntjsgrunt-contrib-uglify

Grunt uglify. How to minify and replace original file with result?


We're using grunt for dev and prod. For dev we don't perform uglify but for prod we do. Unfortunately I can't change references to script from something like this "script.js" to "script.min.js".

I've tried grunt task like this for prod environment but it is not work:

// uglify
uglify: {
    options: {
        drop_console: true
    },
    componet: {
        src:  [componet.path + 'script.js'],
        dest: componet.path + 'script.js'
    },
}

What is the best workflow to change content "script.js" with uglified version?


Solution

  • Try with this:

    uglify: {
        options: {
    
        },
        main: {
            files: [{
                expand: true,
                src: ['yourpath/**/*.js'],
                dest: ''
            }]
        }
    }