This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
/
vue.config.js
86 lines (74 loc) · 1.81 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const CompressionPlugin = require('compression-webpack-plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const IS_PROD = process.env.NODE_ENV === 'production'
const assetsCDN = {
externals: {
vue: 'Vue',
'vue-router': 'VueRouter',
vuex: 'Vuex',
axios: 'axios',
},
css: [],
js: [
'//cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js',
'//cdn.jsdelivr.net/npm/vue-router@3.0.3/dist/vue-router.min.js',
'//cdn.jsdelivr.net/npm/vuex@3.0.1/dist/vuex.min.js',
'//cdn.jsdelivr.net/npm/axios@0.19.0/dist/axios.min.js',
],
}
module.exports = {
publicPath: process.env.VUE_APP_PUBLIC_PATH,
productionSourceMap: false,
devServer: {
host: '0.0.0.0',
proxy: {
[process.env.VUE_APP_REQUEST_BASE_URL]: {
target: process.env.VUE_APP_BASE_API,
changeOrigin: true,
},
},
},
css: {
loaderOptions: {
sass: { data: '@import "@/assets/scss/variables.scss";' },
},
},
chainWebpack: (config) => {
config.resolve.alias
.set('@img', '@/assets/images')
.set('@comp', '@/components')
config
.plugin('html')
.tap((args) => {
args[0].title = process.env.VUE_APP_PAGE_TITLE
if (IS_PROD) {
args[0].cdn = assetsCDN
}
return args
})
},
configureWebpack: (config) => {
config.optimization = {
splitChunks: {
chunks: 'all',
},
}
if (IS_PROD) {
config.plugins.push(
new CompressionPlugin({
test: /\.js$|\.html$|\.css/,
threshold: 8192,
}),
)
config.externals = {
...config.externals,
...assetsCDN.externals,
}
}
if (process.env.VUE_APP_MODE === 'preview') {
config.plugins.push(
new BundleAnalyzerPlugin(),
)
}
},
}