Skip to content

Instantly share code, notes, and snippets.

@wailorman
Created November 2, 2015 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wailorman/0bfe879b1c663999caa7 to your computer and use it in GitHub Desktop.
Save wailorman/0bfe879b1c663999caa7 to your computer and use it in GitHub Desktop.
JSX fast watchify by gulp
var gulp = require('gulp'),
source = require('vinyl-source-stream'),
browserify = require('browserify'),
babelify = require('babelify'),
watchify = require('watchify'),
livereload = require('gulp-livereload');
var bundlePaths = {
src: {
js: [
'src/**/*.js'
],
jsEntry: 'src/main.js'
},
dest: 'dist/'
},
browserifyOpts = {
entries: [bundlePaths.src.jsEntry],
debug: true,
cache: {},
packageCache: {}
},
babelifyOpts = {
presets: ['react', 'es2015']
};
function bundle(bundler) {
return bundler.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest(bundlePaths.dest));
}
gulp.task('watchify', function () {
var bundler = watchify(browserify(browserifyOpts)).transform(babelify, babelifyOpts);
// bundle and fire livereload update event after
bundle(bundler).pipe(livereload());
});
gulp.task('livereload-server', function () {
livereload({start: true});
});
gulp.task('watch', ['livereload-server', 'watchify'], function () {
gulp.watch('src/**/*.js', ['watchify']);
});
{
"devDependencies": {
"babel-preset-es2015": "^6.0.14",
"babel-preset-react": "^6.0.14",
"babelify": "^7.0.2",
"browserify": "^12.0.1",
"gulp": "^3.9.0",
"gulp-livereload": "^3.8.1",
"livereload-js": "^2.2.2",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.6.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment