-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
49 lines (40 loc) · 1.37 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
var gulp = require('gulp')
var sourcemaps = require('gulp-sourcemaps')
var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer')
var browserify = require('browserify')
var watchify = require('watchify')
function compile (watch) {
var bundler = browserify('./src/index.js', { debug: true }).transform('babelify', {presets: ['es2015']})
bundler.bundle()
.on('error', function (err) { console.error(err); this.emit('end') })
.pipe(source('index.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./app'))
}
function watch () {
var bundler = watchify(browserify('./src/index.js', { debug: true }).transform('babelify', {presets: ['es2015']}))
function rebundle () {
bundler.bundle()
.on('error', function (err) { console.error(err); this.emit('end') })
.pipe(source('index.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./app'))
}
if (watch) {
bundler.on('update', function () {
console.log('-> bundling...')
rebundle()
})
}
rebundle()
}
gulp.task('build-js', function () { return compile() })
gulp.task('watch-js', function () { return watch() })
gulp.task('build', ['build-js'])
gulp.task('watch', ['watch-js'])
gulp.task('default', ['build'])