-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.pro.config.js
128 lines (125 loc) · 3.94 KB
/
webpack.pro.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const path = require("path");
const webpack = require('webpack');
const config = require('./webpack.common.config');
const merge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// const UglifyJsPlugin=require('uglifyjs-webpack-plugin');
// webpack4 自动压缩
module.exports = merge(config, {
entry: {
main: [
__dirname + '/src/index.tsx',
],
// antd按需加载跟vendor冲突
// vendor: [
// "react",
// "react-dom",
// "redux",
// "antd"
// ]
},
externals: {
"react": "React",
"react-dom": "ReactDOM",
'redux': 'Redux'
},
output: {
path: __dirname + '/dist',
publicPath: "./",
filename: "bundle.[chunkhash].js",
},
mode: 'production',
module: {
rules: [
{
test: /(\.less)$/,
exclude: /node_modules|antd\.less/,
include:path.resolve('src/'),
use: ExtractTextPlugin.extract({
fallback: {
loader: "style-loader"
},
use: [
{
loader: "css-loader"
},
{
loader: "less-loader",
options: {
javascriptEnabled: true
}
}
]
})
},
]
},
plugins: [
new CleanWebpackPlugin({
root: path.resolve(__dirname, 'dist'),
exclude: ['assets'],
dry: false // 启用删除文件
}),
new ExtractTextPlugin({
filename: '[name].[hash:8].css' // 配置提取出来的css名称
}),
new HtmlWebpackPlugin({
inject: 'body',
template: __dirname + '/public/index.html',
filename: "index.html",
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
// bundle 可视化工具
new BundleAnalyzerPlugin(
{
analyzerMode: 'server',
analyzerHost: '127.0.0.1',
analyzerPort: 8889,
reportFilename: 'report.html',
defaultSizes: 'parsed',
openAnalyzer: true,
generateStatsFile: false,
statsFilename: 'stats.json',
statsOptions: null,
logLevel: 'info'
}
),
// new UglifyJsPlugin()
],
// 提取公共模块
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: "vendor",
chunks: "all"
}
}
},
// 该模块只支持es5 webpack4 默认pro模式开启压缩
// minimizer: [
// new UglifyJsPlugin({
// uglifyOptions: {
// compress: false,
// beautify: false, // 保留制表符
// comments: false // 保留注释
// }
// })
// ]
}
})