Gulp is nodes popular stream based building system, and has been an absolute pleasure to work with. However, as I move from project to project, I often find myself relying on the same tasks.
Whether its minification, or a set of release tasks, the game of copy and paste can be burdensome. No point in reinventing the wheel for a new project, right?
Thats when it struck me. Why not modularize the gulp tasks themselves? That way, I can just pull them into my current projects gulpfile.
register gulp tasks via module.export
Node makes it relatively simple to require and scope methods to a single module.
With gulp specifically, it is relatively easy to import tasks from another file. You do this simply by passing a reference to your initial
Node, by default, will look in our
node_modules directory for a package with the name of gulp-foo
Inside of our module, we may expect to find something like this:
gulp -T will see that
foo is now one of our registered tasks.
We can see that by only have 2 lines in our gulpfile, we’ve opened the door to task modularity and reuse.
strive for modularity with gulp
I am sick to death of writing the same coffee in coffee out task from project to project. It can prove to be pretty monotomnous.
We all have different ways of doing things in our projects, especially with gulp.
But if you think you’ve written a pretty good gulp task, and your proud of it, why not register it on npm? share it with the world
that way the rest of us can stop wasting time putting together our own gulp tasks, we can standardize our projects, and focus on what we love most.
gulp release tasks, a real world example
I’ve applied this concept in a project called gulp release tasks which I hope proves useful to gulp, npm, and bower lovers alike.