Skip to content

Instantly share code, notes, and snippets.

@AllenFang
Last active August 29, 2015 14:17
Show Gist options
  • Save AllenFang/e85f79681e12dfa39dbe to your computer and use it in GitHub Desktop.
Save AllenFang/e85f79681e12dfa39dbe to your computer and use it in GitHub Desktop.
browserify and watchify
gulp.task("build", function(){
//building your app.
});
gulp.task("dev", function(){
gulp.watch("./src/app.js", ['build']);
});
var gulp = require('gulp');
var browserify = require('browserify');
var watchify = require('watchify');
var source = require("vinyl-source-stream");
gulp.task("dev", function(){
//create a browserify instance at first
var b = browserify({
entries: ["./src/app.js"], //entry point
transform: [],
cache: {},
debug: true,
packageCache: {},
fullPaths: true,
});
//create a watchify instance by a browserify instance
b = watchify(b);
//register an update event for watchify
b.on('update', function(){
build(b);
});
build(b);
})
function build(b){
b.bundle()
.pipe(source("bundle.js"))
.pipe(gulp.dest("./build"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment