-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgulpfile.js
51 lines (45 loc) · 1.58 KB
/
gulpfile.js
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
45
46
47
48
49
50
51
'use strict';
var gulp = require('gulp'),
assign = require('lodash.assign'),
browserify = require('browserify'),
buffer = require('vinyl-buffer'),
gutil = require('gulp-util'),
source = require('vinyl-source-stream'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
watchify = require('watchify'),
webserver = require('gulp-webserver');
// custom browserify options
var customOpts = {
entries: ['./src/js/index.js'],
debug: true
};
var opts = assign({}, watchify.args, customOpts);
var b = watchify(browserify(opts));
gulp.task('js', bundle); // 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('bundle.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(uglify()) // minify
.pipe(sourcemaps.write('./')) // writes .map file
.pipe(gulp.dest('./js'));
}
// static web server w/ livereload
gulp.task('server', function() {
gulp.src('./')
.pipe(webserver({
port: 3000,
directoryListing: false,
open: true
}));
});
gulp.task('default', ['js', 'server']);