-
Notifications
You must be signed in to change notification settings - Fork 5
/
devServer.js
48 lines (36 loc) · 1.25 KB
/
devServer.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
#!/usr/bin/env node
require("babel-core/register");
if (process.env.NODE_ENV === undefined) {
throw new Error("NODE_ENV is undefined");
}
const path = require("path");
const express = require("express");
const webpack = require("webpack");
const config = require("./webpack.config.js");
const app = express();
config.devtool = "eval";
config.output.filename = "bundle.js"
config.entry.unshift("webpack-hot-middleware/client");
config.plugins.push(new webpack.optimize.OccurenceOrderPlugin());
config.plugins.push(new webpack.HotModuleReplacementPlugin());
config.plugins.push(new webpack.NoErrorsPlugin());
const compiler = webpack(config);
const devMiddleware = require("webpack-dev-middleware")(compiler, {
publicPath: config.output.publicPath,
stats: {
colors: true
}
})
app.use(this.middleware = devMiddleware);
app.use(require("webpack-hot-middleware")(compiler));
app.get("*", function(req, res) {
var index = this.middleware.fileSystem.readFileSync(path.join(config.output.path, "index.html"));
res.end(index);
}.bind(this));
app.listen(8091, "localhost", function(err) {
if (err) {
console.log(err); // eslint-disable-line no-console
return;
}
console.log("Listening at http://localhost:8091"); // eslint-disable-line no-console
});