简体   繁体   中英

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'
  }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM