-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart-server.js
More file actions
72 lines (62 loc) · 1.56 KB
/
start-server.js
File metadata and controls
72 lines (62 loc) · 1.56 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
63
64
65
66
67
68
69
70
71
72
/* eslint import/no-extraneous-dependencies: 0 */
/* eslint no-console: 0 */
Error.stackTraceLimit = 30;
const respawn = require('respawn');
const webpack = require('webpack');
const webpackBackendConfig = require('./webpack.server.config.js');
webpackBackendConfig.mode = 'development';
const backendCompiler = webpack(webpackBackendConfig);
const STATS_OPTIONS = {
assets: false,
colors: true,
version: false,
modules: false,
hash: false,
timings: false,
chunks: false,
chunkModules: false,
reasons: true,
cached: true,
chunkOrigins: true
};
let lastHash = null;
function backendCompilerCallback(error, stats) {
if (error) {
lastHash = null;
console.error(error.stack || error);
if (error.details) {
console.error(error.details);
}
return;
}
if (stats.hash !== lastHash) {
lastHash = stats.hash;
process.stdout.write(`${stats.toString(STATS_OPTIONS)}\n`);
}
}
backendCompiler.plugin('compile', () => console.log('Building server...'));
let monitor;
backendCompiler.plugin('done', () => {
try {
console.log('Restarting server...');
if (!monitor) {
monitor = respawn(['node', '--harmony', './.build/server.js'], {
cwd: '.',
maxRestarts: 1,
sleep: 100,
kill: 1000,
stdio: [
process.stdin,
process.stdout,
process.stderr
]
});
monitor.start();
} else {
monitor.stop(() => monitor.start());
}
} catch (error) {
console.error(error.toString());
}
});
backendCompiler.watch(100, backendCompilerCallback);