-
Notifications
You must be signed in to change notification settings - Fork 7
/
build-rollup.js
60 lines (36 loc) · 1.02 KB
/
build-rollup.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
// Hack: npm run has poor cross-platform env var support.
if (process.env.DEBUG === undefined) process.env.DEBUG = 'build:*';
const fs = require('fs');
const debug = require('debug')('build:rollup');
const rollup = require('rollup');
const { watch, args } = require('./build-util');
if (args.prod) debug('using prod config');
const config = args.prod
? require('./rollup.config-prod')
: require('./rollup.config-dev');
let cache;
let building = false;
function build() {
if (building) return; // block builds until they finish
debug('bundling');
building = true;
config.cache = cache;
return rollup.rollup(config).then(writeBundle).then(done, error);
}
function writeBundle(bundle) {
cache = bundle;
return bundle.write(config);
}
function done() {
debug(`bundled`);
building = false;
}
function error(err) {
debug('error while bundling:\n' + (err.message || err.stack));
cache = undefined;
building = false;
}
if (args.watch) {
watch('src', { include: /(glsl|js|vue)$/gi }, build);
}
build();