Skip to content

Commit a34dabe

Browse files
committed
webpack 4 upgrade
1 parent 3a9827f commit a34dabe

File tree

4 files changed

+4943
-563
lines changed

4 files changed

+4943
-563
lines changed

Diff for: build/webpack.base.config.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ const webpack = require('webpack')
33
const vueConfig = require('./vue-loader.config')
44
const ExtractTextPlugin = require('extract-text-webpack-plugin')
55
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
6+
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
67

78
const isProd = process.env.NODE_ENV === 'production'
89

9-
module.exports = {
10+
const config = {
1011
devtool: isProd
1112
? false
1213
: '#cheap-module-source-map',
@@ -56,17 +57,32 @@ module.exports = {
5657
maxEntrypointSize: 300000,
5758
hints: isProd ? 'warning' : false
5859
},
60+
mode: process.env.NODE_ENV || 'production',
5961
plugins: isProd
6062
? [
61-
new webpack.optimize.UglifyJsPlugin({
62-
compress: { warnings: false }
63-
}),
6463
new webpack.optimize.ModuleConcatenationPlugin(),
6564
new ExtractTextPlugin({
66-
filename: 'common.[chunkhash].css'
65+
filename: 'common.[chunkhash].css',
66+
allChunks: true
6767
})
6868
]
6969
: [
7070
new FriendlyErrorsPlugin()
7171
]
7272
}
73+
74+
if(isProd) config.optimization = {
75+
...config.optimization,
76+
minimizer: [
77+
new UglifyJsPlugin({
78+
sourceMap: true,
79+
uglifyOptions: {
80+
compress: {
81+
inline: false,
82+
},
83+
},
84+
}),
85+
],
86+
}
87+
88+
module.exports = config

Diff for: build/webpack.client.config.js

+24-19
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,31 @@ const config = merge(base, {
1919
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
2020
'process.env.VUE_ENV': '"client"'
2121
}),
22-
// extract vendor chunks for better caching
23-
new webpack.optimize.CommonsChunkPlugin({
24-
name: 'vendor',
25-
minChunks: function (module) {
26-
// a module is extracted into the vendor chunk if...
27-
return (
28-
// it's inside node_modules
29-
/node_modules/.test(module.context) &&
30-
// and not a CSS file (due to extract-text-webpack-plugin limitation)
31-
!/\.css$/.test(module.request)
32-
)
33-
}
34-
}),
35-
// extract webpack runtime & manifest to avoid vendor chunk hash changing
36-
// on every build.
37-
new webpack.optimize.CommonsChunkPlugin({
38-
name: 'manifest'
39-
}),
22+
4023
new VueSSRClientPlugin()
41-
]
24+
],
25+
optimization:{
26+
runtimeChunk: {
27+
name: "manifest"
28+
},
29+
// extract webpack runtime & manifest to avoid vendor chunk hash changing
30+
// on every build.
31+
// extract vendor chunks for better caching
32+
splitChunks:{
33+
chunks:"initial",
34+
cacheGroups: {
35+
vendors: function (module) {
36+
// a module is extracted into the vendor chunk if...
37+
return (
38+
// it's inside node_modules
39+
/node_modules/.test(module.context) &&
40+
// and not a CSS file (due to extract-text-webpack-plugin limitation)
41+
!/\.css$/.test(module.request)
42+
)
43+
}
44+
}
45+
}
46+
},
4247
})
4348

4449
if (process.env.NODE_ENV === 'production') {

0 commit comments

Comments
 (0)