how to write advanced concat grunt script that fin

2019-08-19 08:24发布

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).

2条回答
霸刀☆藐视天下
2楼-- · 2019-08-19 09:00

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.

查看更多
霸刀☆藐视天下
3楼-- · 2019-08-19 09:02

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'
    }
  }
});
查看更多
登录 后发表回答