Putting it all together
By now, you are probably wondering if it is all worth it. There is just so much to do, with so many plugins and so many tasks and dependencies. Well, fear not. We can combine a lot of tasks in one task to make it easier.
We are going to do all of our JavaScript-related tasks in a single task. We now have the tasks lint
, browserify
, minify-js
, test
, and test-min
. Unfortunately, the lint
and test
steps need to remain separate, but we can Browserify and minify in the same step. To run additional plugins after Browserify, we need to buffer the vinyl streams using the vinyl-buffer
module:
npm install vinyl-buffer --save-dev
After that, we can just pipe browserify
, source
, buffer
, size
, minify
, and dest
in a single task:
return browserify({ entries: [file], debug: true }) .bundle() .pipe(source(file)) .pipe(buffer()) .pipe(rename({ extname: '.bundle.js', dirname: '' })) .pipe(gulp.dest('scripts/bundles')) .pipe(size({ title...