forked from dragonrobotics/PartTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
61 lines (48 loc) · 1.68 KB
/
Copy pathgulpfile.js
File metadata and controls
61 lines (48 loc) · 1.68 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
var browserify = require('browserify');
var envify = require('envify/custom');
var source = require('vinyl-source-stream');
var gulp = require('gulp');
var uglifyjs = require('uglify-es');
var uglify_composer = require('gulp-uglify/composer');
var streamify = require('gulp-streamify');
var gutil = require('gulp-util');
var pump = require('pump');
var uglify = uglify_composer(uglifyjs, console);
function react_browserify(infile, outfile, outdir, debug) {
outfile = (outfile === undefined) ? infile : outfile;
outdir = (outdir === undefined) ? 'static/js' : outdir;
debug = (debug === undefined) ? !gutil.env.production : debug;
var b = browserify('client-js/'+infile+'.jsx', {debug:debug});
b.transform('babelify');
if(!debug) {
b.transform(envify({ NODE_ENV: 'production' }), { global: true });
b.transform('uglifyify', { global: true });
}
function bundlefn(cb) {
pump([
b.bundle(),
source(outfile+'.js'),
debug ? gutil.noop() : streamify(uglify()),
gulp.dest(outdir)
], cb);
}
b.on('log', gutil.log);
return bundlefn;
}
gulp.task('build-spa', react_browserify('SinglePage', 'single'));
gulp.task('build-sw', function(cb) {
var debug = !gutil.env.production;
var b = browserify('client-js/service-worker.js', {debug: debug});
if(!debug) {
b.transform(envify({ NODE_ENV: 'production' }), { global: true });
b.transform('uglifyify', { global: true });
}
b.on('log', gutil.log);
pump([
b.bundle(),
source('service-worker.js'),
debug ? gutil.noop() : streamify(uglify()),
gulp.dest('static/js')
], cb);
});
gulp.task('build', ['build-spa', 'build-sw']);