-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.production.js
77 lines (66 loc) · 1.84 KB
/
webpack.config.production.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
const path = require("path");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const { SourceMapDevToolPlugin } = require("webpack");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
const ZipPlugin = require("zip-webpack-plugin");
const devWebpackConfig = require("./webpack.config");
const NODE_BUILD_DIR = "buildNode";
const isPrerendering = process.env.SCRIVITO_PRERENDER;
function prodWebpackConfig(env = {}) {
const {
mode: _devMode,
target: _devTarget,
devServer: _devServer,
plugins: devPlugins,
...sharedConfig
} = devWebpackConfig({ ...env, production: true });
const sharedPlugins = filterPlugins(
devPlugins,
ReactRefreshWebpackPlugin,
SourceMapDevToolPlugin,
isPrerendering ? undefined : WebpackManifestPlugin
);
const plugins = [new CleanWebpackPlugin(), ...sharedPlugins];
if (!isPrerendering) {
plugins.push(
new ZipPlugin({
filename: "build.zip",
path: "../",
pathPrefix: "build/",
})
);
}
return {
...sharedConfig,
mode: "production",
target: ["web", "es2018"],
plugins,
};
}
function nodeWebpackConfig(env = {}) {
const {
target: _prodTarget,
entry: _prodEntry,
output: prodOutput,
...sharedConfig
} = prodWebpackConfig(env);
return {
...sharedConfig,
target: "node",
entry: { prerender_content: "./prerender_content.js" },
output: {
...prodOutput,
path: path.join(__dirname, NODE_BUILD_DIR),
filename: "[name].js",
},
};
}
function filterPlugins(plugins, ...exclude) {
return plugins.filter(
(plugin) => !exclude.some((c) => c && plugin instanceof c)
);
}
module.exports = isPrerendering
? [prodWebpackConfig, nodeWebpackConfig]
: prodWebpackConfig;