-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
62 lines (51 loc) · 1.54 KB
/
gulpfile.js
File metadata and controls
62 lines (51 loc) · 1.54 KB
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
const path = require('path');
const gulp = require('gulp');
gulp.source = require('vinyl-source-stream')
const browserify = require('browserify');
const babelify = require('babelify');
const watchify = require('watchify');
const JS_SOURCE = path.join(__dirname, 'js');
const JS_ENTRY = path.join(JS_SOURCE, 'app.js');
const JS_BUNDLE = 'bundle.js';
const DEST = path.join(__dirname, 'dist');
const STATIC_GLOBS = [
path.join(__dirname, 'css', '*'),
path.join(__dirname, 'img', '*'),
path.join(__dirname, 'sounds', '*'),
path.join(__dirname, 'node_modules', 'react', 'dist', 'react.js'),
path.join(__dirname, 'node_modules', 'react-dom', 'dist', 'react-dom.js')
];
const bundler = browserify({
entries: JS_ENTRY,
debug: true
}).transform('babelify', {
presets: [['react']],
plugins: [
'transform-async-to-generator',
'transform-es2015-modules-commonjs'
]
});
function bundle(){
return bundler.bundle()
.on('error', console.error.bind(console))
.pipe(gulp.source(JS_BUNDLE))
.pipe(gulp.dest(DEST));
}
function bundleAndwatch() {
return watchify(bundler).bundle()
.on('error', console.error.bind(console))
.pipe(gulp.source(JS_BUNDLE))
.pipe(gulp.dest(DEST));
}
bundler.on('update', bundle);
bundler.on('log', msg => console.log(msg));
gulp.task('bundle', bundle);
gulp.task('static', _ => {
return gulp.src(STATIC_GLOBS)
.pipe(gulp.dest(DEST));
});
gulp.task('build', ['bundle', 'static']);
gulp.task('build-watch', ['build'], function(done) {
gulp.watch(STATIC_GLOBS, ['static']);
bundleAndwatch();
});