forked from 57code/vue-study
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
72 lines (62 loc) · 1.75 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
const port = 7070;
const title = "vue项目最佳实践";
const path = require('path')
function resolve(dir) {
return path.join(__dirname, dir)
}
const bodyParser = require("body-parser");
module.exports = {
publicPath: '/best-practice', // 部署应用包时的基本 URL
devServer: {
port: port,
proxy: {
// 代理 /dev-api/user/login 到 http://127.0.0.1:3000/user/login
[process.env.VUE_APP_BASE_API]: {
target: `http://127.0.0.1:3000/`,
changeOrigin: true,
pathRewrite: {
["^" + process.env.VUE_APP_BASE_API]: ""
}
}
},
// before: app => {
// app.use(bodyParser.json());
// app.post("/dev-api/user/login", (req, res) => {
// const { username } = req.body;
// if (username === "admin" || username === "jerry") {
// res.json({
// code: 1,
// data: username
// });
// } else {
// res.json({
// code: 10204,
// message: "用户名或密码错误"
// });
// }
// });
// app.get("/dev-api/user/info", (req, res) => {
// const auth = req.headers["authorization"];
// const roles = auth.split(' ')[1] === "admin" ? ["admin"] : ["editor"];
// res.json({
// code: 1,
// data: roles
// });
// });
// }
},
configureWebpack: {
// 向index.html注入标题
name: title,
},
chainWebpack(config) {
config.module.rule('svg')
.exclude.add(resolve('./src/icons'))
config.module.rule('icons')
.test(/\.svg$/)
.include.add(resolve('./src/icons')).end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({ symbolId: 'icon-[name]' })
}
};