Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I run the 'min' task twice in Grunt?

Is there a way to run a task twice with different configurations in Grunt? Let's say I have two sets of source files in my project and I want to minify them into two separate, minified output files. Like this:

project
    srcA
        fileA1.js
        fileA2.js
    srcB
        fileB1.js
        fileB2.js

As the expected result, I would like to see fileA.min.js and fileB.min.js. How can I achieve that, as min only seems to support one set of src and dest attributes?

min: {
  dist: {
    src: [  'srcA/*.js'],
    dest: 'fileA.min.js'
  }
}
like image 905
nwinkler Avatar asked Nov 20 '12 16:11

nwinkler


1 Answers

Sure in config object you should configure two min tasks

min: {
  a_file: {
    src : [/* a src */],
    dest : "path_to_a_file"
  },
  b_file: {
    src : [/* b src */],
    dest : "path_to_b_file"
  }
}

After that you can create or rewrite default task or even add it to your custom task:

grunt.registerTask('minify', ['min:a_file', 'min:b_file'])
//or 
grunt.registerTask('build', ['concat', 'min:a_file', 'min:b_file'])

And now you can run tasks:

grunt minify
grunt build
like image 51
Flops Avatar answered Sep 22 '22 20:09

Flops