1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| var watchify = require('watchify'), browserify = require('browserify'), gulp = require('gulp'), source = require('vinyl-source-stream'), buffer = require('vinyl-buffer'), gutil = require('gulp-util'), sourcemaps = require('gulp-sourcemaps'), assign = require('lodash.assign'), rename = require('gulp-rename'), babelify = require('babelify'), uglify = require('gulp-uglify'), exit = require('gulp-exit');
var customOpts = { entries: ['./src/app.js'], debug: true, transform: [babelify] }; var opts = assign({}, watchify.args, customOpts); var b = watchify(browserify(opts));
gulp.task('js', bundle); b.on('update', bundle); b.on('log', gutil.log);
function bundle() { return b.bundle() .on('error', gutil.log.bind(gutil, 'Browserify Error')) .pipe(source('./src/app.js')) .pipe(buffer()) .pipe(sourcemaps.init({loadMaps: true})) .pipe(gutil.env.type === 'production' ? uglify() : gutil.noop()) .pipe(rename({ dirname: '' })) .pipe(sourcemaps.write('./')) .pipe(gulp.dest('./dist')) .pipe(gutil.env.type === 'production' ? exit() : gutil.noop()); }
|