This repository has been archived by the owner on Oct 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.babel.js
68 lines (56 loc) · 1.51 KB
/
gulpfile.babel.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import gulp from 'gulp';
import browserSync from 'browser-sync';
import uglify from 'gulp-uglify';
import size from 'gulp-size';
import del from 'del';
import runSequence from 'run-sequence';
const bs = browserSync.create();
// https://github.com/gulpjs/gulp/blob/master/docs/recipes/fast-browserify-builds-with-watchify.md
import browserify from 'browserify';
import watchify from 'watchify';
import source from 'vinyl-source-stream';
let b = browserify({
entries: ['./app/scripts/app.js'],
debug: true
}, watchify.args);
// only watch for changes in development mode
if (process.env.GULP_ENV !== 'production') {
b = watchify(b);
}
function bundle() {
return b.bundle()
.on('error', msg => {
delete msg.stream;
$.util.log(msg);
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('.tmp/scripts'))
.pipe(bs.stream({once: true}));
}
gulp.task('scripts', bundle);
b.on('update', bundle);
gulp.task('connect', ['scripts'], done => {
bs.init({
notify: false,
port: 9000,
server: {
baseDir: ['.tmp', 'app']
}
}, done);
});
gulp.task('watch', ['connect'], () => {
gulp.watch([
'app/index.html'
]).on('change', bs.reload);
});
gulp.task('serve', ['connect', 'watch']);
gulp.task('compress', () => {
gulp.src('.tmp/scripts/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist/scripts'))
.pipe(size({gzip: false}));
});
gulp.task('clean', del.bind(null, ['.tmp', 'dist']));
gulp.task('default', (done) => {
runSequence('clean', 'scripts', 'compress', done);
})