Skip to content

Commit cb4dcd9

Browse files
committed
增加了环境配置信息
1 parent ebab77c commit cb4dcd9

5 files changed

Lines changed: 29 additions & 18 deletions

File tree

.github/workflows/Frontend.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ jobs:
1919
- name: build
2020
run: |
2121
cd Frontend
22-
npm install && npm run build
22+
npm install
23+
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
24+
npm run build -- --mode production
25+
else
26+
npm run build -- --mode test
27+
fi
2328
- name: Deploy to Server
2429
uses: easingthemes/ssh-deploy@v2.1.5
2530
env:
26-
SSH_PRIVATE_KEY: ${{ github.ref == 'refs/heads/master' && secrets.PROD_SSH_PRIVATE_KEY || secrets.DEV_SSH_PRIVATE_KEY }}
31+
SSH_PRIVATE_KEY: ${{ github.ref == 'refs/heads/master' && secrets.PROD_SSH_PRIVATE_KEY || secrets.TEST_SSH_PRIVATE_KEY }}
2732
REMOTE_HOST: ${{ github.ref == 'refs/heads/master' && secrets.PROD_REMOTE_HOST || secrets.TEST_REMOTE_HOST }}
2833
REMOTE_USER: root
2934
SOURCE: Frontend/dist/*

Frontend/.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_API_BASE_URL=http://localhost:8000/

Frontend/.env.production

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_API_BASE_URL=

Frontend/.env.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_API_BASE_URL=

Frontend/vite.config.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
import { defineConfig } from 'vite'
1+
import { defineConfig, loadEnv } from 'vite'
22
import vue from '@vitejs/plugin-vue'
33

44
import tailwindcss from '@tailwindcss/vite'
55

66
// https://vite.dev/config/
7-
export default defineConfig({
8-
plugins: [vue(), tailwindcss()],
9-
resolve: {
10-
alias: {
11-
'@': '/src',
7+
export default defineConfig(({ mode }) => {
8+
const env = loadEnv(mode, process.cwd(), '')
9+
10+
return {
11+
plugins: [vue(), tailwindcss()],
12+
resolve: {
13+
alias: {
14+
'@': '/src',
15+
},
1216
},
13-
},
14-
server: {
15-
port: 5173,
16-
proxy: {
17-
'/api': {
18-
target: "http://127.0.0.1:8000/",
19-
changeOrigin: true, //需要代理跨域
20-
rewrite: (path) => path.replace(/^\/api/, ''), //路径重写,把'/api'替换为''
17+
server: {
18+
proxy: {
19+
'/api': {
20+
target: env.VITE_API_BASE_URL,
21+
changeOrigin: true, //需要代理跨域
22+
rewrite: (path) => path.replace(/^\/api/, ''), //路径重写,把'/api'替换为''
23+
},
2124
},
2225
},
23-
},
24-
})
26+
}
27+
})

0 commit comments

Comments
 (0)