Vue2.7 + Vite+ Eslint、Stylelint、Commitlint 统一开发规范
+ husky + lint-staged (git commit 时自动格式化代码)
+ Vue 全家桶集成
+ Axios 封装及接口管理
https://juejin.cn/post/7118700020911570974
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
874 B
38 lines
874 B
2 years ago
|
/**
|
||
|
* { prefix: '/demo', target: 'http://localhost:3000/demo', removePrefix: true }
|
||
|
* 最终会被转化为
|
||
|
* {
|
||
|
* '/demo': {
|
||
|
* target: 'http://localhost:3000/demo',
|
||
|
* changeOrigin: true,
|
||
|
* ws: true,
|
||
|
* rewrite: path => path.replace(new RegExp('^/demo'), '')
|
||
|
* }
|
||
|
* }
|
||
|
*/
|
||
|
const proxyList = [
|
||
|
{ prefix: '/demo', target: 'http://localhost:3000/demo', removePrefix: true },
|
||
|
{ prefix: '/api', target: 'http://localhost:3000/api' }
|
||
|
]
|
||
|
|
||
|
export default proxyList.reduce((pre, cur) => {
|
||
|
const { prefix, target, removePrefix, ...res } = cur
|
||
|
|
||
|
// https://www.vitejs.net/config/#server-proxy
|
||
|
const proxyOpts = {
|
||
|
target,
|
||
|
changeOrigin: true,
|
||
|
ws: true,
|
||
|
...res
|
||
|
}
|
||
|
|
||
|
// 移除前缀
|
||
|
if (removePrefix) {
|
||
|
proxyOpts.rewrite = path => path.replace(new RegExp(`^${prefix}`), '')
|
||
|
}
|
||
|
|
||
|
pre[prefix] = proxyOpts
|
||
|
|
||
|
return pre
|
||
|
}, {})
|