-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvue.config.js
46 lines (45 loc) · 1.37 KB
/
vue.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
const LodashPlugin = require('lodash-webpack-plugin')
const MomentLocalesPlugin = require('moment-locales-webpack-plugin')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const WebpackBundleAnalyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
module.exports = {
publicPath: './',
chainWebpack: config => {
config
.plugin('lodash').use(LodashPlugin).end()
.plugin('moment').use(MomentLocalesPlugin).end()
config
.devServer.disableHostCheck(true).end()
config.optimization.splitChunks({
cacheGroups: {
common: {
name: 'common',
chunks: 'all',
minSize: 20,
minChunks: 2
}
}
})
// 构建分析
if (process.env.NODE_ENV === 'production') {
config.externals({
vue: 'Vue',
moment: 'moment',
'vue-router': 'VueRouter'
})
config.plugin('html').tap(options => {
options[0].minify.removeAttributeQuotes = false
return options
}).end()
config.plugin('compress').use(CompressionWebpackPlugin, [{
test: /\.js$|\.html$|\.css$/,
threshold: 0, // 超过10kb就压缩
deleteOriginalAssets: false
}])
if (process.env.npm_config_report) {
config.plugin('analyzer').use(WebpackBundleAnalyzer).end()
config.plugins.delete('prefetch')
}
}
}
}