@rob_rich
by Rob Richardson
June 18, 2014
Rob Richardson is a local software craftsman building web properties in ASP.NET and Node. He's a frequent speaker at conferences, user groups, and community events, and a diligent teacher and student of high quality software development. You can find this and other talks on http://robrich.org/presentations and follow him on twitter at @rob_rich.
The streaming build system
FAQ
Is it "gulp" or "Gulp"?
gulp is always lowercase.
source: https://github.com/gulpjs/gulp/blob/master/docs/FAQ.md
gulp.src('./**/*.js')
.pipe(jshint())
.pipe(jshint.reporter())
.pipe(uglify())
.pipe(concat('all.min.js'))
.pipe(header('/** Copyright '+new Date().getFullYear()+' **/'))
.pipe(gulp.dest('build/js'));
Traditional build systems:
|
gulp:
|
gulp.src('./**/*.js')
.pipe(jshint())
.pipe(jshint.reporter())
.pipe(uglify())
.pipe(concat('all.min.js'))
.pipe(header('/** Copyright '+new Date().getFullYear()+' **/'))
.pipe(gulp.dest('build/js'));
src.pipe(dest)
from stream handbook
a.pipe(b).pipe(c).pipe(d)
Bash:
a | b | c | d
from stream handbook
var through2 = require('through2');
a.pipe(through2.obj(function (data, enc, cb) {
// do something with data object
this.push(data);
cb();
}))
.pipe(b)
gulp task1 task2
Can install it globally
npm install -g gulp
Or rig it through npm run commands in package.json:
npm install --save-dev gulp
...
},
"scripts": {
"test": "gulp test",
"watch": "gulp watch"
},
"devDependencies": {
"gulp": "^3.8.0",
...
var through2 = require('through2');
module.exports = function (opts) {
return through2.obj(function (file, enc, cb) {
// do something with vinyl fs file
file.contents = Buffer.concat([opts.text, file.contents]);
this.push(file);
cb();
};
};
add keyword "gulpplugin" (if it works with vinyl-fs files)
or "gulpfriendly" (if it doesn't)
...
},
"keywords": [
"gulpplugin"
],
"dependencies": {
"through2": "^0.4.2",
...
Your gulpfile is just a JavaScript file
Don't build a plugin to do normal Node tasks
function startExpress() {
var express = require('express');
var app = express();
app.use(require('connect-livereload')());
app.use(express.static(__dirname));
app.listen(4000);
}
Your gulpfile is just a JavaScript file
Don't build a plugin to do normal Node tasks
(it's a great way to get your plugin blacklisted)
You're locked into plugin's library version