From 786a58c2619d078d98a1ff7be316ed5c688310f7 Mon Sep 17 00:00:00 2001 From: kubbo <390378816@qq.com> Date: Thu, 24 Apr 2025 15:52:17 +0800 Subject: [PATCH] =?UTF-8?q?build(web):=20=E9=85=8D=E7=BD=AE=20Vite=20?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E7=AB=AF=E5=8F=A3=E5=92=8C=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 .env 文件,将 WEB_PORT 改为 VITE_WEB_PORT - 删除 web/README.md 文件 - 更新 vite.config.js 文件,添加端口和代理配置 --- .env | 2 +- web/README.md | 29 ----------------------------- web/vite.config.js | 23 ++++++++++++++++------- 3 files changed, 17 insertions(+), 37 deletions(-) delete mode 100644 web/README.md diff --git a/.env b/.env index 32b034e..1bbdd86 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ SERVER_PORT = 8080 -WEB_PORT = 80 \ No newline at end of file +VITE_WEB_PORT = 80 \ No newline at end of file diff --git a/web/README.md b/web/README.md deleted file mode 100644 index d863828..0000000 --- a/web/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# web - -This template should help get you started developing with Vue 3 in Vite. - -## Recommended IDE Setup - -[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur). - -## Customize configuration - -See [Vite Configuration Reference](https://vite.dev/config/). - -## Project Setup - -```sh -npm install -``` - -### Compile and Hot-Reload for Development - -```sh -npm run dev -``` - -### Compile and Minify for Production - -```sh -npm run build -``` diff --git a/web/vite.config.js b/web/vite.config.js index d49d708..baa9e99 100644 --- a/web/vite.config.js +++ b/web/vite.config.js @@ -6,15 +6,24 @@ import vueJsx from '@vitejs/plugin-vue-jsx' import vueDevTools from 'vite-plugin-vue-devtools' // https://vite.dev/config/ + export default defineConfig({ - plugins: [ - vue(), - vueJsx(), - vueDevTools(), - ], + plugins: [vue(), vueJsx(), vueDevTools()], resolve: { alias: { - '@': fileURLToPath(new URL('./src', import.meta.url)) + '@': fileURLToPath(new URL('./src', import.meta.url)), }, }, -}) + server: { + // 使用 import.meta.env.VITE_WEB_PORT 来读取 .env 文件中的环境变量 + port: 3000, + // 新增正向代理配置 + proxy: { + '/api': { + target: 'http://127.0.0.1:8080/api', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, ''), + }, + }, + }, +}) \ No newline at end of file