Created
November 2, 2015 22:43
-
-
Save wailorman/0bfe879b1c663999caa7 to your computer and use it in GitHub Desktop.
JSX fast watchify by gulp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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