feat: 精简模板代码
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# 端口号
|
||||
VITE_PORT=5666
|
||||
VITE_PORT=17001
|
||||
|
||||
VITE_BASE=/
|
||||
# 是否开启 Nitro Mock服务,true 为开启,false 为关闭
|
||||
@@ -10,7 +10,8 @@ VITE_DEVTOOLS=false
|
||||
VITE_INJECT_APP_LOADING=true
|
||||
|
||||
# 后台请求路径 具体在vite.config.mts配置代理
|
||||
VITE_GLOB_API_URL=http://localhost:19001/api/app
|
||||
VITE_GLOB_API_URL="/dev-api"
|
||||
VITE_APP_URL="http://localhost:19001/api/app"
|
||||
|
||||
# 全局加密开关(即开启了加解密功能才会生效 不是全部接口加密 需要和后端对应)
|
||||
VITE_GLOB_ENABLE_ENCRYPT=false
|
||||
|
||||
@@ -16,8 +16,7 @@ VITE_INJECT_APP_LOADING=true
|
||||
VITE_ARCHIVER=true
|
||||
|
||||
# 后端接口地址
|
||||
# VITE_GLOB_API_URL=/prod-api
|
||||
VITE_GLOB_API_URL=https://yiapi.wjys.top/api
|
||||
VITE_GLOB_API_URL=/prod-api
|
||||
|
||||
# 全局加密开关(即开启了加解密功能才会生效 不是全部接口加密 需要和后端对应)
|
||||
VITE_GLOB_ENABLE_ENCRYPT=false
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { defineConfig } from '@vben/vite-config';
|
||||
|
||||
import { loadEnv } from "vite";
|
||||
// 自行取消注释来启用按需导入功能
|
||||
// import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
|
||||
// import Components from 'unplugin-vue-components/vite';
|
||||
|
||||
export default defineConfig(async () => {
|
||||
export default defineConfig(async ({ command, mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), "");
|
||||
return {
|
||||
application: {},
|
||||
vite: {
|
||||
@@ -23,12 +24,33 @@ export default defineConfig(async () => {
|
||||
],
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
[env.VITE_GLOB_API_URL]: {
|
||||
target: env.VITE_APP_URL,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, ''),
|
||||
// mock代理目标地址
|
||||
target: 'http://localhost:19001/api/app',
|
||||
rewrite: (path) => path.replace(`${[env.VITE_GLOB_API_URL]}`, ""),
|
||||
|
||||
//查看真实代理url
|
||||
bypass(req, res, options) {
|
||||
const proxyUrl = options.target + options.rewrite(req.url);
|
||||
console.log(proxyUrl);
|
||||
req.headers['X-req-proxyURL'] = proxyUrl;
|
||||
res.setHeader('X-req-proxyURL', proxyUrl);
|
||||
}
|
||||
},
|
||||
[env.VITE_APP_BASE_WS]: {
|
||||
target: env.VITE_APP_BASE_URL_WS,
|
||||
changeOrigin: true,
|
||||
rewrite: (p) => p.replace( `${[env.VITE_APP_BASE_WS]}`, ""),
|
||||
ws: true,
|
||||
//查看真实代理url
|
||||
bypass(req, res, options) {
|
||||
|
||||
const proxyUrl = options.target + options.rewrite(req.url);
|
||||
// console.log(proxyUrl);
|
||||
req.headers['X-req-proxyURL'] = proxyUrl;
|
||||
res.setHeader('X-req-proxyURL', proxyUrl);
|
||||
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user