Search code examples
javascriptgruntjsgrunt-contrib-uglifyuglifyjs2

Replace js files with the corresponding minified versions


I'm using Grunt and I want minify my js files (I'm trying to config uglify https://github.com/gruntjs/grunt-contrib-uglify but without success...)

I would like replace all js files in my project with corrispondents file minified.

If, for example, my project structure is

|
|__js
|  |___home.js
|
|__app
|  |___order.js
|  |___fld
|      |___simple.js
|      |___break.js
|
|__foo.js
|
|__login
|  |__offline.js
|
|__best.js

I would like simply, for each file, replace it with the minified version (with same nemes, without merge their in one file)

I have tried with:

    uglify: {
        minAllJs: {
            files: [
                {'**/*.js':['**/*.js']}
            ]
        }
    },

but not work...

p.s. I don't want write

{'js/home.js':['js/home.js']}
{'app/order.js':['app/order.js']}
{'app/fld/simple.js':['app/fld/simple.js']}
{'app/fld/break.js':['app/fld/break.js']}
{'foo.js':['foo.js']}
{'login/offline.js':['login/offline.js']}
{'best.js':['best.js']}

because my structure folder change and I don't want every time modify the Gruntfile


Solution

  • Try with this:

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