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'
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With