-
-
Save heshanlk/53e331fd58fac5f3e45ab2b50cdae82d to your computer and use it in GitHub Desktop.
gulpfile.js with browserify, reactify, watchify and gulp-notify.
This file contains hidden or 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 source = require('vinyl-source-stream'); | |
var gulp = require('gulp'); | |
var gutil = require('gulp-util'); | |
var browserify = require('browserify'); | |
var reactify = require('reactify'); | |
var watchify = require('watchify'); | |
var notify = require("gulp-notify"); | |
var scriptsDir = './scripts'; | |
var buildDir = './build'; | |
function handleErrors() { | |
var args = Array.prototype.slice.call(arguments); | |
notify.onError({ | |
title: "Compile Error", | |
message: "<%= error.message %>" | |
}).apply(this, args); | |
this.emit('end'); // Keep gulp from hanging on this task | |
} | |
// Based on: http://blog.avisi.nl/2014/04/25/how-to-keep-a-fast-build-with-browserify-and-reactjs/ | |
function buildScript(file, watch) { | |
var props = {entries: [scriptsDir + '/' + file]}; | |
var bundler = watch ? watchify(props) : browserify(props); | |
bundler.transform(reactify); | |
function rebundle() { | |
var stream = bundler.bundle({debug: true}); | |
return stream.on('error', handleErrors) | |
.pipe(source(file)) | |
.pipe(gulp.dest(buildDir + '/')); | |
} | |
bundler.on('update', function() { | |
rebundle(); | |
gutil.log('Rebundle...'); | |
}); | |
return rebundle(); | |
} | |
gulp.task('build', function() { | |
return buildScript('main.js', false); | |
}); | |
gulp.task('default', ['build'], function() { | |
return buildScript('main.js', true); | |
}); |
This file contains hidden or 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
{ | |
"name": "scripts", | |
"version": "0.0.0", | |
"description": "", | |
"main": "gulpfile.js", | |
"devDependencies": { | |
"envify": "~1.2.1", | |
"react": "~0.10.0", | |
"browserify": "~4.2.0", | |
"gulp": "~3.8.5", | |
"gulp-notify": "~1.4.0", | |
"gulp-util": "~2.2.19", | |
"reactify": "~0.13.1", | |
"vinyl-source-stream": "~0.1.1", | |
"watchify": "~0.10.2" | |
}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "BSD-2-Clause" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment