-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
89 lines (85 loc) · 1.99 KB
/
webpack.config.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* @file 配置文件
*/
const path = require("path");
const HTMLWebpackPlugin = require("html-webpack-plugin");
const resolve = (p) => path.resolve(__dirname, "../", p);
const PrerenderSPAPlugin = require("prerender-spa-plugin");
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer;
const plugins = [
new HTMLWebpackPlugin({
template: "index.html",
}),
];
if (process.env.NODE_ENV === "production") {
plugins.push(
new PrerenderSPAPlugin({
staticDir: path.join(__dirname, "dist"),
routes: ["/"],
renderer: new Renderer({
headless: true,
renderAfterDocumentEvent: "render-event",
// renderAfterDocumentEvent: "custom-render-trigger",
}),
})
);
}
module.exports = {
devtool: false,
resolve: {
extensions: [".js", ".jsx", ".san", ".json", ".ts"],
alias: {
"@src": resolve("example/src/"),
},
},
entry: [path.join(__dirname, "src", "main.js")],
output: {
path: path.join(__dirname, "dist"),
publicPath: '/',
},
devServer: {
before: (app) => {
app.all("*", function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
// eslint-disable-next-line
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
next();
});
},
port: 10086,
open: true,
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: "babel-loader",
},
{
test: /\.san$/,
use: "san-loader",
},
{
test: /\.(png|jpe?g|gif|svg|woff2?|eot|ttf|otf)(\?.*)?$/,
use: [
{
loader: "url-loader",
options: {
limit: 10000,
},
},
],
},
{
test: /\.css/,
use: ["style-loader", "css-loader"],
},
],
},
plugins,
};