-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvue.config.js
73 lines (71 loc) · 1.84 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
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
const path = require('path');
function resolve(dir) {
return path.join(__dirname, dir);
}
module.exports = {
outputDir: process.env.outputDir,
publicPath: process.env.baseUrl,
assetsDir: 'static',
chainWebpack: (config) => {
// :todo 有条件的话,可以抽离element-ui 等比较大的依赖到cdn上
config.resolve.alias
.set('@$', resolve('src'))
.set('assets', resolve('src/assets'))
.set('utils', resolve('src/utils'))
.set('components', resolve('src/components'));
// 移除 prefetch 插件
config.plugins.delete('prefetch');
// 添加svg处理loader
config.module
.rule('svgSpriteLoader')
.test(/\.svg$/)
.include
.add(resolve('src/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
.end();
config.module
.rule('svg')
.exclude
.add(resolve('src/icons'))
.end();
// 仅仅在uat 和生产环境生成文件大小日志
if (process.env.NODE_ENV !== 'development') {
config.plugin('analyzer')
.use(BundleAnalyzerPlugin)
.end();
}
// 压缩图片
config.module
.rule("image-webpack-loader")
.test(/\.(gif|png|jpe?g|svg)$/i)
.use("file-loader")
.loader("image-webpack-loader")
.tap(() => ({
disable: process.env.NODE_ENV !== "production"
}))
.end();
},
// 反向代理
devServer: {
port: 8010,
hotOnly: true,
host: '0.0.0.0',
open: true,
https: false,
proxy: {
'/api': {
target: 'https://www.easy-mock.com/mock/5c7794e135c5e14db980feed/admin',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
}
}
};