-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
61 lines (50 loc) · 1.31 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
52
53
54
55
56
57
58
59
60
61
'use strict';
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const browserify = require('browserify');
const watchify = require('watchify');
const babelify = require('babelify');
const brfs = require('brfs');
const paths = {
src: './frontend',
entryPoint: 'app.js',
dest: 'assets/js'
};
const compile = function(watch) {
let br = browserify('./frontend/app.js', { debug: true });
let bundler;
br.transform(babelify);
br.transform(brfs);
bundler = watchify(br);
function rebundle() {
bundler.bundle()
.on('error', function(err) { console.error(err); this.emit('end'); })
.pipe(source(paths.entryPoint))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.dest));
}
if (watch) {
bundler.on('update', function() {
console.log('-> bundling...');
rebundle();
});
}
rebundle();
};
const watch = function() {
return compile(true);
};
gulp.task('watch:browserify', function() {
return watch();
});
gulp.task('watch', [
'watch:browserify'
]);
gulp.task('build', function() {
return compile();
});
gulp.task('default', ['watch']);