-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.client.legacy.js
116 lines (113 loc) · 3 KB
/
webpack.client.legacy.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const path = require("path")
const webpack = require("webpack")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const TerserJSPlugin = require("terser-webpack-plugin")
const ModuleHtmlPlugin = require("./module-html-plugin")
const {
isDEV,
babelPresets,
babelPlugins,
webpackResolve,
getCommandArg,
commonRules,
webpackSplitChunks,
} = require("./webpack.common.js")
// const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
// .BundleAnalyzerPlugin
const settedBabelPlugins = !isDEV
? [
...babelPlugins,
["transform-remove-console", { exclude: ["error", "warn"] }],
]
: [...babelPlugins, "react-hot-loader/babel"]
const webpackAlias = isDEV
? {
"react-dom": "@hot-loader/react-dom",
}
: {}
module.exports = {
target: ["web", "es5"],
entry: {
client: path.resolve(__dirname, "./src/client/index.js"),
},
output: {
publicPath: isDEV ? "/" : "/public/",
// filename: `application-[${isDEV ? "chunkhash" : "contenthash"}].js`,
filename: isDEV
? "[name]-[hash]-legacy.js"
: `[name]-[contenthash]-legacy.js`,
chunkFilename: isDEV
? "[name]-[hash]-legacy.js"
: `[name]-[contenthash]-legacy.js`,
path: path.resolve(__dirname, "public"),
},
devtool: isDEV ? "eval-cheap-source-map" : "nosources-source-map",
resolve: {
...webpackResolve,
alias: webpackAlias,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: "babel-loader",
options: {
presets: [babelPresets("legacy"), "@babel/preset-react"],
plugins: [...settedBabelPlugins],
},
exclude: /node_modules\/(?!(swr|react-use-gesture|react-spring))/,
},
...commonRules(),
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "./public/build/views/index.html"),
filename: path.join(__dirname, "./public/views/index.html"),
minify: {
collapseWhitespace: true,
removeComments: false,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
},
}),
new webpack.DefinePlugin({
RENDER_OPTS: JSON.stringify(getCommandArg("render")),
}),
new ModuleHtmlPlugin(true),
],
optimization: {
minimize: !isDEV,
minimizer: !isDEV
? [
new TerserJSPlugin({
terserOptions: {
parse: {
ecma: 8,
},
compress: {
ecma: 2015,
warnings: false,
},
mangle: {
safari10: true,
},
output: {
ecma: 5,
comments: false,
safari10: true,
},
safari10: true,
},
extractComments: false,
parallel: true,
sourceMap: true,
}),
]
: [],
runtimeChunk: true,
splitChunks: webpackSplitChunks,
},
}