-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.config.js
98 lines (97 loc) · 2.6 KB
/
webpack.prod.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
90
91
92
93
94
95
96
97
98
const path =require('path')
const webpack = require('webpack')
const ManifestPlugin = require('webpack-manifest-plugin')
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlwebpackPlugin = require('html-webpack-plugin')
const ReactLoadablePlugin = require('react-loadable/webpack').ReactLoadablePlugin;
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
mode: 'production',
entry: [
'./src/client.jsx',
],
resolve: {
extensions: ['.jsx', '.js']
},
output: {
path: path.join(__dirname, 'dist'),
filename: "js/[name].[chunkhash:6].js",
publicPath: '/dist/',
chunkFilename: 'js/[name].bundle.[chunkhash:6].js',
},
module: {
rules: [
{
test: /\.(jsx|js)$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader?cacheDirectory",
}
]
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
]
},
]
},
plugins: [
new ManifestPlugin(),
new HtmlwebpackPlugin({
template: './src/template.html',
}),
new ReactLoadablePlugin({
filename: './dist/react-loadable.json',
}),
new MiniCssExtractPlugin({
filename: 'css/[name].[chunkhash:6].css',
chunkFilename: 'css/[name].[chunkhash:6].css',
}),
new CompressionWebpackPlugin({
filename: '[path].gz[query]',// 目标文件名
algorithm: 'gzip',// 使用gzip压缩
test: /\.js$|\.css$|\.html$|\.eot?.+$|\.ttf?.+$|\.woff?.+$|\.svg?.+$/,
threshold: 10240,// 资源文件大于10240B=10kB时会被压缩
minRatio: 0.8 // 最小压缩比达到0.8时才会被压缩
}),
new webpack.HashedModuleIdsPlugin(),
new ScriptExtHtmlWebpackPlugin({
defaultAttribute: 'defer',
})
],
optimization: {
minimizer: [new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true
},
output: {
comments: false
}
}
})],
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,//(react|react-dom|redux|react-redux|redux-thunk)[\\/]
name: 'vendor',
chunks: 'all'
}
}
}
}
}