1

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?

1
  • a-ha-ha, well, you can use grunt to compule your gulpfile.js and then run it ))) Commented Dec 1, 2014 at 11:26

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.