Skip to content

Commit 0f9ab09

Browse files
committed
refactor: update webpack config to use TerserPlugin and MiniCssExtractPlugin
1 parent 26788f6 commit 0f9ab09

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

build/webpack.prod.conf.js

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
var path = require('path')
22
var config = require('../config')
33
var utils = require('./utils')
4-
var webpack = require('webpack')
5-
var merge = require('webpack-merge')
6-
var baseWebpackConfig = require('./webpack.base.conf')
7-
var ExtractTextPlugin = require('extract-text-webpack-plugin')
8-
var HtmlWebpackPlugin = require('html-webpack-plugin')
4+
const webpack = require('webpack')
5+
const { merge } = require('webpack-merge')
6+
const baseWebpackConfig = require('./webpack.base.conf')
7+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
8+
const HtmlWebpackPlugin = require('html-webpack-plugin')
9+
const TerserPlugin = require('terser-webpack-plugin')
910

1011
var env
1112
if (process.env.NODE_ENV === 'testing') {
@@ -18,33 +19,23 @@ console.log('webpack env :\n', env)
1819

1920
var webpackConfig = merge(baseWebpackConfig, {
2021
module: {
21-
loaders: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true })
22+
rules: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true })
2223
},
23-
devtool: config.build.productionSourceMap ? '#source-map' : false,
24+
devtool: config.build.productionSourceMap ? 'source-map' : false,
2425
output: {
2526
path: config.build.assetsRoot,
26-
filename: utils.assetsPath('js/[name].[chunkhash].js'),
27-
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
28-
},
29-
vue: {
30-
loaders: utils.cssLoaders({
31-
sourceMap: config.build.productionSourceMap,
32-
extract: true
33-
})
27+
filename: utils.assetsPath('js/[name].[contenthash].js'),
28+
chunkFilename: utils.assetsPath('js/[id].[contenthash].js')
3429
},
3530
plugins: [
3631
// http://vuejs.github.io/vue-loader/workflow/production.html
3732
new webpack.DefinePlugin({
3833
'process.env': env
3934
}),
40-
new webpack.optimize.UglifyJsPlugin({
41-
compress: {
42-
warnings: false
43-
}
44-
}),
45-
new webpack.optimize.OccurenceOrderPlugin(),
4635
// extract css into its own file
47-
new ExtractTextPlugin(utils.assetsPath('css/[name].[contenthash].css')),
36+
new MiniCssExtractPlugin({
37+
filename: utils.assetsPath('css/[name].[contenthash].css')
38+
}),
4839
// generate dist index.html with correct asset hash for caching.
4940
// you can customize output by editing /index.html
5041
// see https://github.com/ampedandwired/html-webpack-plugin

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@
7070
"vue-loader": "^15.10.1",
7171
"vue-style-loader": "^4.1.3",
7272
"vue-template-compiler": "",
73-
"webpack": "^5.64.4",
74-
"webpack-dev-middleware": "^5.2.1",
75-
"webpack-hot-middleware": "^2.25.0",
76-
"webpack-merge": "^5.8.0"
73+
"webpack": "^5.89.0",
74+
"webpack-dev-middleware": "^5.3.3",
75+
"webpack-hot-middleware": "^2.25.1",
76+
"webpack-merge": "^5.9.0",
77+
"terser-webpack-plugin": "^5.3.9",
78+
"mini-css-extract-plugin": "^2.7.5"
7779
}
7880
}

0 commit comments

Comments
 (0)