Skip to content

Instantly share code, notes, and snippets.

@yanak
Created April 27, 2015 02:32
Show Gist options
  • Save yanak/754fae7ba51006bbf5d9 to your computer and use it in GitHub Desktop.
Save yanak/754fae7ba51006bbf5d9 to your computer and use it in GitHub Desktop.
Browserify + Reactify + watchify + gulpでReactの開発をする ref: http://qiita.com/ytanak/items/d81f7b1307058bd46fd2
'use strict';
var watchify = require('watchify');
var browserify = require('browserify');
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var gutil = require('gulp-util');
var sourcemaps = require('gulp-sourcemaps');
var assign = require('lodash.assign');
var reactify = require('reactify');
// add custom browserify options here
var customOpts = {
entries: ['./src/main.js'],
transform: [reactify],
debug: true
};
var opts = assign({}, watchify.args, customOpts);
var b = watchify(browserify(opts));
gulp.task('js', bundle); // so you can run `gulp js` to build the file
b.on('update', bundle); // on any dep update, runs the bundler
b.on('log', gutil.log); // output build logs to terminal
function bundle() {
return b.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('app.js'))
// optional, remove if you don't need to buffer file contents
.pipe(buffer())
// optional, remove if you dont want sourcemaps
.pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file
// Add transformation tasks to the pipeline here.
.pipe(sourcemaps.write('./')) // writes .map file
.pipe(gulp.dest('../../../../public/js'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment