-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.production.js
121 lines (118 loc) · 3.5 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
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
117
118
119
120
121
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const FavIconsWebpackPlugin = require("favicons-webpack-plugin");
const path = require("path");
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const cleanOptions = {
verbose: true,
dry: false
};
const config = {
devtool: false,
entry: ["./src/index.ts"],
output: {
path: path.resolve("dist"),
filename: "[name].[hash].js"
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"]
},
module: {
rules: [
{test: /\.tsx?$/, loader: "babel-loader"},
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
{loader: "css-loader", options: {importLoaders: 1}},
"postcss-loader",
"sass-loader"
]
},
{
loader: "webpack-ant-icon-loader",
enforce: "pre",
options: {
chunkName: "antd-icons"
},
include: [require.resolve("@ant-design/icons/lib/dist")]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ["file-loader"]
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html"
}),
new FavIconsWebpackPlugin({
logo: "./src/assets/yetric-icon.png"
}),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
}),
new CleanWebpackPlugin(cleanOptions),
new MiniCssExtractPlugin({
filename: "[name].[hash].css",
chunkFilename: "[id].[hash].css"
}),
new OptimizeCssAssetsPlugin({
canPrint: true,
cssProcessorPluginOptions: {
preset: ["default", {discardComments: {removeAll: true}}]
}
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
parse: {
ecma: 8
},
compress: {
ecma: 5,
warnings: false,
comparisons: false
},
mangle: {
safari10: true
},
output: {
ecma: 5,
comments: false,
ascii_only: true
},
parallel: true,
cache: true
}
})
],
splitChunks: {
chunks: (chunk) => {
return chunk.name !== "antd-icons";
},
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
}
}
};
module.exports = config;