pedrommuller
pedrommuller

Reputation: 16066

Configure grunt.js to minify files one by one in bower folder

I have the dependencies of the application in bower_components, some of the dependencies don't have a minified version so I'd like to create a task creates a minified copy of the file version in the same place where the file is located like:

This is my grunt Config so far:

 uglify: {
        dev: {
            files:[
            {
                expand: true,
                src: 'bower_components/modernizr/modernizr.js',
                dest: '/',
                ext:'.min.js'
            }, {
                expand: true,
                src: 'bower_components/angular-facebook/lin/angular-facebook.js',
                dest: '/',
                ext: '.min.js'
            }]
            },
                main: {
                    src: 'temp/app.min.js',
                    dest:'dist/app.min.js'
                }
            }

the Grunt task says that copied modernizr to it's own folder but when I look at it, the file is not there and after the first file Grunt passes to the next task and ignores the 'second' file in the array.

I was just testing this obviously I'd like to implement a way that grunt scan all the dependencies in bower_components automatically.

btw, I don't mind to change the task to any other library.

Upvotes: 0

Views: 341

Answers (1)

hereandnow78
hereandnow78

Reputation: 14434

the / in your dest-option means the root path (were your gruntfile resides). just delete the dest-option or put an empty string there.

important: this just works with the expand-option set!

{
  expand: true,
  src: 'bower_components/modernizr/modernizr.js',
  ext:'.min.js'
}

Edit:

for scanning all folders an minimizing all js files do it like this (note the second argument in src to not minify files which are already minified):

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

Upvotes: 1

Related Questions