Skip to content

Instantly share code, notes, and snippets.

@takashi
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save takashi/88b663d818f880f6cbcf to your computer and use it in GitHub Desktop.

Select an option

Save takashi/88b663d818f880f6cbcf to your computer and use it in GitHub Desktop.
build with browserify and watchify
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var del = require ('del');
var watchify = require('watchify');
var browserify = require('browserify');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var source = require('vinyl-source-stream');
var assign = require('lodash.assign');
var opts = {
entries: ['./app/assets/javascripts/index.js'],
debug: true
};
var opts = assign({}, watchify.args, opts);
var b = watchify(browserify(opts));
gulp.task('js', bundle);
b.on('update', bundle);
b.on('log', gutil.log);
gulp.task('build', ['js']);
function bundle() {
return b.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('index.js'))
.pipe(gulp.dest('app/assets/javascripts/dist/'));
};
{
"name": "name",
"version": "1.0.0",
"description": "desc",
"private": true,
"scripts": {
"watch": "$(npm bin)/gulp js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Takashi Nakagawa",
"devDependencies": {
"browser-sync": "^2.5.0",
"browserify": "^9.0.3",
"del": "^1.1.1",
"gulp": "^3.8.11",
"gulp-util": "^3.0.4",
"lodash.assign": "^3.1.0",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment