-
Notifications
You must be signed in to change notification settings - Fork 15
/
vue.config.js
98 lines (97 loc) · 2.57 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
87
88
89
90
91
92
93
94
95
96
97
98
// 引入配置文件config.js
const conf = require('./src/config/config.ts')
const { defineConfig } = require('@vue/cli-service')
const webpack = require('webpack')
module.exports = defineConfig({
productionSourceMap: false, //不生成map文件
transpileDependencies: true,
lintOnSave: false,
parallel: false,
chainWebpack: config => {
// Markdown文件
config.module.rule('md')
.test(/\.md/)
.use('vue-loader')
.loader('vue-loader')
.end()
.use('vue-markdown-loader')
.loader('vue-markdown-loader/lib/markdown-compiler')
.options({
raw: true
})
// 导入cdn静态文件连接 来自config.ts
config.plugin('html').tap(args => {
args[0].cdn = conf.STATIC_CDN
return args
})
if (conf.PRODUCTION) {
// 删除预加载优化
config.plugins.delete('preload')
config.plugins.delete('prefetch')
// 压缩优化
config.optimization.minimize(true)
// 分割优化
config.optimization.splitChunks({
chunks: 'all'
})
// 清除生成环境的console.log输出
config.optimization
.minimizer('terser')
.tap(args => {
Object.assign(args[0].terserOptions.compress, {
pure_funcs: ['console.log']
})
return args
})
}
},
configureWebpack: {
// cdn的方式引入js文件等
externals: conf.EXTERNALS,
optimization: {
splitChunks: {
cacheGroups: {
// node_modules目录下的库剥离
vendor: {
chunks: 'all',
test: /node_modules/,
name: 'vendor',
minChunks: 1,
maxInitialRequests: 5,
minSize: 0,
priority: 100
},
// 公用|自定义模块剥离
common: {
chunks: 'all',
test: /[\\/]src[\\/](utils|config|service|router|store|directive)[\\/]/,
name: 'common',
minChunks: 1,
maxInitialRequests: 5,
minSize: 0,
priority: 60
},
runtimeChunk: {
name: 'manifest'
}
}
}
}
},
devServer: {
host: conf.DEV_HOST, // dev环境主机地址
port: conf.DEV_PORT, // dev环境默认端口
proxy: {
[conf.PROXY_ROOT]: {
target: conf.BASE_URL, // 设置地址代替axios的BASE_URL
ws: true, // 代理 websocket
changeOrigin: true, // 跨域
secure: true, // https接口
// 路径重写
pathRewrite: {
['^${conf.PROXY_ROOT}']: '/'
}
}
}
}
})