-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.dev.ts
39 lines (32 loc) · 968 Bytes
/
webpack.dev.ts
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
import { merge } from "webpack-merge";
const common = require("./webpack.common.ts");
const path = require("path");
import * as Session from "./server/session";
module.exports = merge(common, {
mode: "development",
devtool: "eval-source-map",
devServer: {
port: 8080,
static: "./public",
setupMiddlewares: (middlewares: any, devServer: any) => {
setupDev(devServer);
return middlewares;
},
},
});
const setupDev = async (devServer: any) => {
const { app, compiler } = devServer;
await Session.setupSession(app);
app.use("*", (req: any, res: any) => {
const filename = path.join(compiler.outputPath, "index.html");
compiler.outputFileSystem.readFile(filename, (err: any, result: any) => {
if (err) {
res.status(404).sendFile(path.resolve(__dirname, "public/error.html"));
return;
}
res.set("Content-Type", "text/html");
res.send(result);
res.end();
});
});
};