How to import all tasks from another gulp file.js

落花浮王杯 提交于 2020-01-12 02:43:49

问题


Is it possible to have one main gulpfile.js from which to call tasks from other gulp files.js? Simple "require" of child gulpfile.js into main one doesn't work. I have a platform project which includes several sub projects with separate gulpfiles, so I need a solution to manage all child gulpfiles from within main one


回答1:


It is possible to have one main gulpfile.js from which to call tasks from other gulp files.js using the require-dir module. From the projects README use it like this:


Split tasks across multiple files

If your gulpfile.js is starting to grow too large, you can split the tasks into separate files by using the require-dir module.

Imagine the following file structure:

gulpfile.js
tasks/
├── dev.js
├── release.js
└── test.js

Install the require-dir module:

npm install --save-dev require-dir

Add the following lines to your gulpfile.js file.

var requireDir = require('require-dir');
var dir = requireDir('./tasks');



回答2:


I've create a special gulp-require-tasks module that will help you to split your gulpfile.js into separate smaller task files. Please see the README for example and documentation.

Please consider using it and let me know if it works for you! If you have any suggestions or ideas for improvement, I will gladly accept them.



来源:https://stackoverflow.com/questions/25518870/how-to-import-all-tasks-from-another-gulp-file-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!