我可以在我的代码组织项目中使用多个gruntjs文件吗? [英] Can I have multiple gruntjs files in my project for code organization?

查看:80
本文介绍了我可以在我的代码组织项目中使用多个gruntjs文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的项目使用gruntjs,并想知道在我的项目中是否可能有多个grunt.js文件?我问的原因是我的项目是这样组织的:

  grunt.js 
|
| - project1
| |
| | -grunt.js
|
| - project2
|
| - project3(etc ..)

我想要顶级grunt.js建立所有的项目。然而,随着项目列表的增加,我不希望我的顶级grunt.js文件变得巨大。所以我想组织它,这样最高级别的grunt可以调用项目级别的grunt文件来构建它们。或者如果有人想构建project1,他们可以到project1文件夹并运行它自己的grunt.js。这可以做到吗?如果是这样,我该如何调用其他grunt文件?如果不是,那么除了拥有一个巨大的grunt.js文件之外,还有什么替代解决方案?感谢。

解决方案

有一个叫做 grunt-hub 似乎正在做你想做的事情。


grunt-hub:



一个Grunt任务,用于在多个Grunt项目上观察和运行任务。

集线器任务



集线器任务用于在多个项目上运行任务。它想知道要使用哪个Gruntfiles以及在每个Grunt项目上运行哪些任务。例如,如果我想要在每个Grunt项目中对一个文件夹进行绒毛和测试:


我没有使用它,但它可能会符合你的要求。你也可以考虑更低层次的 grunt-exec 或创建自己的任务来产生子进程。


I'm using gruntjs for my project and was wondering if it's possible to have multiple grunt.js files in my project? The reason I'm asking is that my project is organized like so:

grunt.js
|
|- project1
|   |
|   |-grunt.js
|
|- project2
|
|- project3 (etc..)

I want the top level grunt.js to build all the projects. However as the list of projects grow I don't want my top level grunt.js file to become huge. So I would like to organize it so that the top level grunt can call the project level grunt files to build them. Or if someone wants to just build project1, they can go to the project1 folder and run it's own grunt.js. Can this be done? If so, how do I call the other grunt files? If not, then what's an alternative solution other than having one huge grunt.js file? Thanks.

解决方案

There's a grunt task called grunt-hub which seems to do what you want to do.

grunt-hub:

A Grunt task to watch and run tasks on multiple Grunt projects.

hub task

The hub task is for running tasks on multiple projects. It would like to know which Gruntfiles to use and which tasks to run on each Grunt project. For example if I would like to lint and test on every Grunt project one folder up:

I haven't used it, but it might meet your requirements. Also you might want to look into more lower level such as grunt-exec or creating your own tasks to spawn child processes.

这篇关于我可以在我的代码组织项目中使用多个gruntjs文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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