问题
I need to write an advanced concat script using grunt. here is my boilerplate:
___js
|____dist
| |____vents
| | |____commonEvents.js
| | |____compare.js
|____libs
|____src
| |____events
| | |____carousel.common.js
| | |____compare.js
| | |____styles.common.js
| |____handlers
| | |____carousel.common.js
| | |____compare.js
| | |____style.common.js
I want the concat task to look into "src/events" and "src/handlers" directory and find all the files ending with ".common.js" and concat them together and put them in the "dist/vents" directory ("commonEvents.js"), other files that are not ending with ".common.js" I want the script to find the pair in the other directory and concat them together and put them into "dis/vents/filename.js" (example: events/compare.js and handlers/compare.js are pair and not ending with common.js).
回答1:
I guess that we already know about https://github.com/gruntjs/grunt-contrib-concat module. You just need two different tasks. What about this:
grunt.initConfig({
concat: {
common: {
src: ['src/events/**/*.common.js', 'src/handlers/**/*.common.js'],
dest: 'dist/vents/commonEvents.js'
},
nocommon: {
src: ['src/events/**/*.js', 'src/handlers/**/*.js', '!src/events/**/*.common.js', '!src/handlers/**/*.common.js'],
dest: 'dist/vents/filename.js'
}
}
});
回答2:
I don't think there is anything similar ready to use.
If you plan to create your own solution, I think this package can be a good starting point:
https://github.com/yeoman/grunt-usemin
It manipulates the config of other plugins as well.
来源:https://stackoverflow.com/questions/20082257/how-to-write-advanced-concat-grunt-script-that-find-matches-in-seperate-folders