-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (70 loc) · 1.77 KB
/
index.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
76
77
78
79
80
81
var fs = require('fs')
var browserify = require('browserify')
var watchify = require('watchify')
var babelify = require('babelify')
var assign = require('lodash.assign')
var nodemon = require('nodemon')
var builds = [
{
_name: 'Server',
_ignore: ['./app/'],
_opts: {
entries: ['server/index.js'],
outfile: 'dist/server.js',
builtins: false,
browserField: false,
insertGlobalVars:
{ process: undefined,
global: undefined,
'Buffer.isBuffer': undefined,
Buffer: undefined }
}
},
{
_name: 'App',
_ignore: ['./server/'],
_opts: {
entries: ['app/index.js'],
outfile: 'dist/app.js',
builtins: undefined,
browserField: true,
insertGlobalVars: undefined
}
}];
function startWatcher(build) {
var opts = assign({
cache: {},
ignoreWatch: ['**/node_modules/**', './dist/'].concat(build._ignore),
packageCache: {},
plugin: [watchify, babelify],
debug: true
}, build._opts);
var b = browserify(opts);
b.on('update', bundle);
b.on('log', function (msg) {
console.log('\x1b[32m [' + build._name + ']' + '\x1b[0m => ' + msg);
});
b.on('error', function (msg) {
console.log('\x1b[32m [ERROR] \x1b[0m');
});
function bundle() {
b.bundle()
.pipe(fs.createWriteStream(build._opts.outfile))
}
bundle();
return build._name;
}
var watchedBuilds = builds.map(startWatcher);
// Nodemon conf.
nodemon({
script: 'dist/server.js',
ignore: ['dist/app.js', 'app/*']
});
nodemon.once('start', function () {
console.log('Server has started.');
}).on('quit', function () {
console.log('\nNodemon stopped. Press CMD+q to exit.');
}).on('restart', function (files) {
console.log('Server restarted ( file changed: %s)', files);
});
console.log('Watching files. Ready to build ' + watchedBuilds.join(', ') );