-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
development_server.js
76 lines (62 loc) · 1.61 KB
/
development_server.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* eslint-disable no-console */
var fs = require('fs');
var rollup = require('rollup');
var nodeResolve = require('rollup-plugin-node-resolve');
var commonjs = require('rollup-plugin-commonjs');
var json = require('rollup-plugin-json');
var http = require('http');
var gaze = require('gaze');
var ecstatic = require('ecstatic');
var building = false;
var cache;
if (process.argv[2] === 'develop') {
build();
gaze(['modules/**/*.js', 'data/**/*.{js,json}'], function(err, watcher) {
watcher.on('all', function() {
build();
});
});
http.createServer(
ecstatic({ root: __dirname, cache: 0 })
).listen(8080);
console.log('Listening on :8080');
} else {
build();
}
function unlink(f) {
try { fs.unlinkSync(f); } catch (e) { /* noop */ }
}
function build() {
if (building) return;
// Start clean
unlink('dist/iD.js');
unlink('dist/iD.js.map');
building = true;
console.log('Rebuilding');
console.time('Rebuilt');
rollup.rollup({
entry: './modules/id.js',
plugins: [
nodeResolve({
jsnext: true, main: true, browser: false
}),
commonjs(),
json()
],
cache: cache
}).then(function (bundle) {
bundle.write({
format: 'iife',
dest: 'dist/iD.js',
sourceMap: true,
useStrict: false
});
building = false;
cache = bundle;
console.timeEnd('Rebuilt');
}, function(err) {
building = false;
cache = undefined;
console.error(err);
});
}