gulp.task('task-A', function () {
// Do A here!
};
gulp.task('task-B', function() {
// Do B here!
});
gulp.task('task-C', ['task-B'], function() {
// Do C here, but wait for B to complete!
});
gulp.task('main', ['task-A', 'task-C']);
Good old *ASYNC* tasks
gulp.task('task-A', function () {
return iPromiseIWillDoA();
};
gulp.task('task-B', function(cb) {
// Do B
if(everythingIsOk()) {
return cb();
}
cb('Error!');
});
gulp.task('task-C', ['task-B'], function() {
return streamOfCoolThingsForC();
});
Getting the Files
gulp.task('cool-build', function () {
return gulp.src(['src/**/*.js', 'extra/**/*.js']);
};
var through = require('through2'),
PluginError = require('gulp-util').PluginError;
module.exports = function(opts) {
return through.obj(function(file, enc, callback) {
if (file.isBuffer()) {
// Process file, contents are a buffer
} else if (file.isStream()) {
// Process file, contents are in a stream
}
if(someError) {
this.emit('error', new PluginError(myPluginName, someError));
} else {
this.push(file);
}
callback();
});
};
No need to plugin: Browserify
gulp.task('build:js', ['clean:js'], function () {
return browserify({
entries: './main',
noParse: ['jquery'],
basedir: APP_SRC_DIR
}).exclude('jquery')
.bundle() // Up to here is normal browserify stuff!
.pipe(source(require('./package.json').name + '.min.js'))
// From here we have a Vinyl File stream
.pipe(streamify(uglify({
preserveComments: 'some'
})))
.pipe(gulp.dest(OUTPUT_DIR + 'js'));
});
No need to plugin: Karma
var karma = require('karma'),
karmaConfig = require('./karma.conf.js');
gulp.task('karma', ['dist'], function (cb) {
karma.server.start(karmaConfig, cb);
});