-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathvue.config.js
82 lines (78 loc) · 2.24 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
/* eslint-disable @typescript-eslint/no-var-requires */
const bodyParser = require('body-parser')
const mockServer = require('./src/utils/mock/server');
const { NODE_ENV, VUE_APP_PORT, VUE_APP_MOCK } = process.env;
module.exports = {
publicPath: '/',
outputDir: 'dist',
productionSourceMap: false,
devServer: {
port: VUE_APP_PORT || 8000,
// 配置反向代理
/*
proxy: {
'/api': {
target: '<url>',
ws: true,
changeOrigin: true
},
'/foo': {
target: '<other_url>'
}
},
*/
before: function(app, server) {
if(NODE_ENV === 'development' && VUE_APP_MOCK === 'true') {
// parse app.body
// https://expressjs.com/en/4x/api.html#req.body
// create application/json parser
app.use(bodyParser.json());
// create application/x-www-form-urlencoded parser
app.use(bodyParser.urlencoded({ extended: false}));
mockServer(app);
}
}
},
css: {
loaderOptions: {
less: {
javascriptEnabled: true,
}
}
},
// 修改webpack的配置
configureWebpack: {
// 不需要打包的插件
externals: {
// 'vue': 'Vue',
// 'vue-router': 'VueRouter',
}
},
chainWebpack(config) {
// 内置的 svg Rule 添加 exclude
config.module
.rule('svg')
.exclude.add(/iconsvg/)
.end();
// 添加 svg-sprite-loader Rule
config.module
.rule('svg-sprite-loader')
.test(/.svg$/)
.include.add(/iconsvg/)
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader');
// 添加 svgo Rule
config.module
.rule('svgo')
.test(/.svg$/)
.include.add(/iconsvg/)
.end()
.use('svgo-loader')
.loader('svgo-loader')
.options({
// externalConfig 配置特殊不是相对路径,起始路径是根目录
externalConfig: './src/assets/iconsvg/svgo.yml',
});
}
}