-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-dev-server-compiler.js
63 lines (52 loc) · 1.52 KB
/
server-dev-server-compiler.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
// the server compilation process is running in it's own process
var webpack = require("webpack");
var webpackConfig = require("./webpack/webpack.config");
let compilerServerConfig, compilerServer;
function start(config) {
if (compilerServer) throw new Error("server compilation is started!");
compilerServerConfig = webpackConfig(config);
compilerServer = webpack(compilerServerConfig);
compilerServer.watch({}, (err, stats) => {
const { hash, startTime, endTime } = stats;
console.log(
`webpack built ${hash} in ${endTime - startTime}ms (server-side)`
);
if (err) {
console.error(
"Error: an error occured while compiling the server-side bundle"
);
console.error("----------------");
console.error(err);
console.error("----------------");
return;
}
if (stats.hasErrors()) {
console.error(
"Error: an error occured while compiling the server-side bundle"
);
const { errors } = stats.toJson("errors-only");
for (const error of errors) {
console.error("----------------");
console.error(error);
}
console.error("----------------");
return;
}
const { assetsByChunkName } = stats.toJson({ chunks: true });
process.send({
assetsByChunkName
});
});
}
process.on("message", msg => {
switch (msg.cmd) {
case "start": {
start(msg.config);
break;
}
default: {
console.error(`[${process.pid}] unknown command "${msg.cmd}"`);
break;
}
}
});