-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
38 lines (38 loc) · 1.2 KB
/
server.js
File metadata and controls
38 lines (38 loc) · 1.2 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
const webpack = require("webpack");
const package = require("./package.json");
const webpackDevMiddleware = require("webpack-dev-middleware");
var http = require("http");
const express = require("express");
const app = express();
const config = require("./webpack.dev");
const compiler = webpack(config);
const child_process = require("child_process");
const url = `http://localhost:${package.port}${package.page}`;
// Tell express to use the webpack-dev-middleware and use the webpack.config.js
// configuration file as a base.
app.use(
webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
logLevel: "error"
})
);
app.use(
require("webpack-hot-middleware")(compiler, {
log: console.log,
path: "/__webpack_hmr",
heartbeat: 10 * 1000
})
);
// Serve the files on port.
var server = http.createServer(app);
server.listen(package.port, function () {
console.log("Listening on %j", server.address());
if (process.platform === "win32") {
cmd = "start";
} else if (process.platform === "linux") {
cmd = "xdg-open";
} else if (process.platform === "darwin") {
cmd = "open";
}
child_process.exec(`${cmd} ${url}`);
});