Fun with Gulp
I’ve been a happy Grunt user for a while now. I use it for dev watch/preprocessing/livereload type stuff, and it works great. It is, however, a bit cantankerous to set up. Sometimes you can’t seem to get around making intermediary files when stringing tasks together either, which means crud in your folders. I hate folder crud.
Gulp is the new hot stuff for task running. I hadn’t heard of it until a few weeks ago, but after having a play with it it might replace Grunt in my stack. The configuration is easier to set up and read, and because it uses node streams it can net you a decent performance boost.
Here’s a config file I just made for one of my projects.
1 | // Load plugins |
For my web projects, I generally have two workflows. During dev, I watch JavaScript source files and concatenate them, watch less files and preprocess and minify them, and watch HTML and image files for changes, using livereload to refresh the browser as necessary. Then for build I minify images, uglify the JavaScript, and do some cache busting. To keep my HTML, JS, and CSS in sync, I load JS and CSS with a foo=XXXXXX argument. When I push a new build I replace the XXXXXX number with a random number, invalidating the browser’s cache. I was able to replicate all of this with Gulp in under an hour of Googling.
It’s a little faster and easier to configure than Grunt, but not so much so that you should drop whatever you’re doing and replace your Grunt workflow immediately. Still, for new projects or if you’re just getting into task runners, make Gulp your first stop.