-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.js
More file actions
64 lines (54 loc) · 1.78 KB
/
server.js
File metadata and controls
64 lines (54 loc) · 1.78 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
/**
* Setup and run the development server for Hot-Module-Replacement
* https://webpack.github.io/docs/hot-module-replacement-with-webpack.html
*/
const express = require("express");
const webpack = require("webpack");
const webpackDevMiddleware = require("webpack-dev-middleware");
const webpackHotMiddleware = require("webpack-hot-middleware");
const { spawn } = require("child_process");
// didn't work out. See comment in this file: const config = require("./webpack.for-dev-mode.js");
const config = require("./webpack.renderer-process.hot-reload.js");
const argv = require("minimist")(process.argv.slice(2));
const app = express();
const compiler = webpack(config);
const PORT = process.env.PORT || 3000;
const wdm = webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
stats: {
colors: true,
},
});
app.use(wdm);
app.use(webpackHotMiddleware(compiler));
const server = app.listen(PORT, "localhost", (serverError) => {
if (serverError) {
return console.error(serverError);
}
if (argv["start-hot"]) {
spawn("npm", ["run", "start-hot"], {
shell: true,
env: process.env,
stdio: "inherit",
})
.on("close", (code) => process.exit(code))
.on("error", (spawnError) => console.error(spawnError));
}
if (argv["start-hot-vscode"]) {
spawn("npm", ["run", "start-hot-vscode"], {
shell: true,
env: process.env,
stdio: "inherit",
})
.on("close", (code) => process.exit(code))
.on("error", (spawnError) => console.error(spawnError));
}
console.log(`Listening at http://localhost:${PORT}`);
});
process.on("SIGTERM", () => {
console.log("Stopping dev server");
wdm.close();
server.close(() => {
process.exit(0);
});
});