如何编写高级的concat grunt脚本来查找独立文件夹中的匹配项? [英] how to write advanced concat grunt script that find matches in seperate folders?

查看:108
本文介绍了如何编写高级的concat grunt脚本来查找独立文件夹中的匹配项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用grunt编写高级的concat脚本。这是我的样板:

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

我想要concat任务查看src / events和 src / handlers目录下,找到所有以.common.js结尾的文件,并将它们连接在一起,并放入dist / vents目录(commonEvents.js),其他文件不以结尾。 common.js我希望脚本在另一个目录中找到对并将它们连接在一起并将它们放入dis / vents / filename.js(例如:events / compare.js和handlers / compare.js是pair和不是以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).

推荐答案

我想我们已经知道 https://github.com/gruntjs/grunt-contrib-concat 模块。你只需要两个不同的任务。这是什么:

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

这篇关于如何编写高级的concat grunt脚本来查找独立文件夹中的匹配项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆