-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvue.config.js
72 lines (68 loc) · 2.07 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
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
/*
* @Descripttion:
* @version:
* @Author: Lqi
* @Date: 2021-07-22 09:57:37
* @LastEditors: Please set LastEditors
* @LastEditTime: 2021-08-16 17:34:03
*/
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const isProd = process.env.NODE_ENV === 'production'
// const assetsCDN = {
// externals: {
// // vue: 'vue',
// 'vue-router': 'vueRouter',
// vuex: 'vuex',
// axios: 'axios',
// 'nprogress': 'NProgress'
// },
// css: ['https://cdn.bootcss.com/nprogress/0.2.0/nprogress.min.css'],
// js: [
// // 'https://cdn.bootcdn.net/ajax/libs/vue/3.1.5/vue.global.min.js',
// 'https://cdn.bootcdn.net/ajax/libs/vue-router/4.0.0/vue-router.global.min.js',
// 'https://cdn.bootcdn.net/ajax/libs/vuex/4.0.2/vuex.global.min.js',
// 'https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js',
// 'https://cdn.bootcss.com/nprogress/0.2.0/nprogress.min.js'
// ]
// }
const vueConfig = {
publicPath: '/',
lintOnSave: undefined,
configureWebpack: config => {
if (isProd) {
/* gzip */
// const productionGzipExtensions = ['html', 'js', 'css']
/* cdn */
// config.externals = assetsCDN.externals
config.plugins.push(
new CompressionWebpackPlugin({
filename: '[path][base].gz',
algorithm: 'gzip',
test: /\.(js|css|less)$/,
threshold: 20480, // 只有大小大于该值的资源会被处理 10240
minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
deleteOriginalAssets: false // 删除原文件
})
)
}
config.performance = {
hints: 'warning',
maxEntrypointSize: 50000000,
maxAssetSize: 30000000,
assetFilter: function(filename) {
return filename.endsWith('.js')
}
}
// externals:
},
chainWebpack: config => {
config.plugin('html').tap(args => {
// 生产环境或本地需要cdn时,才注入cdn
if (isProd) args[0].cdn = {}
return args
})
},
productionSourceMap: false,
transpileDependencies: []
}
module.exports = vueConfig