Reputation: 4440
I am loving gulpjs
, but am having an issue where my gulpfile.js
is just getting really, really big.
I have searched pretty extensively and am having difficulty finding resources related to this, but is it possible to split a gulpfile.js
up into multiple smaller js
files just for organization?
Upvotes: 1
Views: 1068
Reputation: 2704
I do it this way (I use coffeescript, but the theory is sound), similar to the above:
tasks = fs.readdirSync './gulp/tasks'
tasks.forEach (task)->
require "./tasks/#{task}" if task.indexOf('coffee') >= 0
All it does is read the task folder and require all the files in it as long as they're .coffee files (which isn't 100% kosher, but it does avoid hidden dotfiles).
Upvotes: 1
Reputation: 4572
Yes, you can do it to manage your tasks. For example if you have this file organization:
gulpfile.js
-- tasks
---- test.js
---- dev.js
You have to install de require-div module:
npm install require-dir --save-dev
And, finally, you add this code to your gulpfile
var requireDir = require('require-dir');
var dir = requireDir('./tasks');
Hope it helps.
Regards.
Upvotes: 4