Gulp Recipes - Part One
04 April 2015 by @ddprrt | Posted in: gulp, tools
After answering about 30 questions or so, I saw that while their issues seem to be unique, the solutions to them are often nearly the same. Focussing on the problems that lie underneath, I tried to compile a list of recipes which might help you with your own gulpy hiccups.
To make it more easily digestible, I’ll start with three recipes for now, continuing this series over time.
Conditionally delete files
There was one user having fun with TypeScript, and putting the output of every compiled
.ts file into the same directory. This directory also contains other
globby) to recreate the same file selection mechanism we know from Gulp. The output is different: Instead of getting a stream of vinyl objects, we get an array of filenames. And this array we are going to manipulate by replacing the file extension (
.ts) with a new one.
Please note that we don’t need any Gulp plugins or similar. Everything is done using standard node modules. One of the bigger strengths of Gulp.
Stopping `gulp.watch` after some time
In this issue, Stack Overflow user Finglish wanted to know how to stop Gulp’s watch process after being idle for some time. You can use that to be reminded of your own laziness or – more likely – to kill demanding processes should you have forgotten them. The latter one actually happens lots of time to me.
I included this one in this series because you’ll learn that
gulp.watch has more to offer than just a simple watch process:
Same task, different configurations
This one I do get a lot: What if you want to run the same task, but with different configurations. Take this configuration object for example:
We want to run all of those to a pipeline of task which is absolutely identical. The only things different are inputs and outputs. We can achieve this by creating a so called stream array:
This pattern can be used by many problems. We had something similar last time when we created multiple Browserify bundles.
Me again. The Gulp, Yeoman, Bower book is pretty sweet. Just saying.
Comments? Shoot me a tweet!