Last active
August 29, 2015 14:22
-
-
Save hiddentao/0c9137e72493e3be26ce to your computer and use it in GitHub Desktop.
Gulp + Browserify + Watchify for building JS code
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
browserify = require 'browserify' | |
source = require 'vinyl-source-stream2' | |
uglify = require 'gulp-uglify' | |
watchify = require 'watchify' | |
gulp = require 'gulp' | |
gutil = require 'gulp-util' | |
gulp.task 'js', -> | |
_process = (b) -> | |
b.bundle() | |
.on 'error', (err) -> | |
gutil.log(err.stack) | |
.pipe source('app.js') | |
.pipe uglify() | |
.pipe gulp.dest(paths.build.js) | |
b = browserify( | |
entries: './src/app.js' | |
debug: true | |
cache: {} | |
packageCache: {} | |
) | |
# From http://christianalfoni.github.io/javascript/2014/08/15/react-js-workflow.html | |
if options.watchify | |
b = watchify(b) | |
.on 'update', -> | |
gutil.log 'Rerunning browserify...' | |
updateStart = Date.now() | |
_process(b) | |
gutil.log '...Done (' + (Date.now() - updateStart) + 'ms)' | |
# kick-off | |
_process(b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment