File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,7 +8,9 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
88
99// https://vitejs.dev/config/
1010export default defineConfig ( ( { mode } ) => {
11- const env = loadEnv ( mode , process . cwd ( ) + '/../' )
11+ // 在 Docker 环境中,父目录可能没有 .env 文件,使用当前目录
12+ const envDir = process . env . DOCKER_BUILD ? __dirname : path . resolve ( __dirname , '../' )
13+ const env = loadEnv ( mode , envDir )
1214
1315 const apiBaseUrl = env . VITE_API_BASE_URL || 'http://127.0.0.1:8483'
1416 const port = parseInt ( env . VITE_FRONTEND_PORT || '3015' , 10 )
Original file line number Diff line number Diff line change @@ -36,10 +36,10 @@ WORKDIR /tmp/frontend
3636COPY ./BillNote_frontend/package.json ./
3737RUN pnpm install
3838
39- # 复制 .env.example 到父目录,供 vite.config.ts 使用
40- COPY ./.env.example /tmp/.env
41-
4239COPY ./BillNote_frontend /tmp/frontend
40+
41+ # 设置环境变量,告诉 vite.config.ts 这是 Docker 构建
42+ ENV DOCKER_BUILD=1
4343RUN pnpm run build
4444
4545# === 阶段3:完整应用镜像 ===
You can’t perform that action at this time.
0 commit comments