Skip to content

Commit d931838

Browse files
committed
feat: add environment-aware base path configuration:
- Configure dynamic base path for local (/) and production (/test-abb/) - Update Vite config to use VITE_BASE_PATH environment variable - Make React Router basename dynamic using BASE_URL - Add build args support in Dockerfile for different environments - Update CI/CD workflow to set base path for GitHub Pages deployment - Simplify README to focus on Docker deployment - Enhance .gitignore with comprehensive exclusions
1 parent 3240e16 commit d931838

5 files changed

Lines changed: 13 additions & 17 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
run: yarn lint
3232

3333
- name: Build
34+
env:
35+
VITE_BASE_PATH: /test-abb/
3436
run: yarn build
3537

3638
- name: Cypress run
@@ -96,6 +98,8 @@ jobs:
9698
with:
9799
context: .
98100
push: true
101+
build-args: |
102+
VITE_BASE_PATH=/test-abb/
99103
# Using the lowercase environment variable to ensure push success
100104
tags: |
101105
ghcr.io/${{ env.REPO_OWNER }}/test-abb:latest

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Build Stage
22
FROM node:20-alpine as build
33
WORKDIR /app
4+
# Accept build argument for base path (defaults to / for local development)
5+
ARG VITE_BASE_PATH=/
6+
ENV VITE_BASE_PATH=$VITE_BASE_PATH
47
COPY package.json yarn.lock ./
58
RUN yarn install --frozen-lockfile
69
COPY . .

README.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,17 @@ graph LR
5656
### Prerequisites
5757

5858
* Docker & Docker Compose
59-
* Node.js (v20+) (Optional, for local non-docker dev)
6059

61-
### Option A: Run with Docker (Recommended)
60+
### Run with Docker
6261

63-
This mirrors the production environment using the optimized Nginx image.
62+
This uses the optimized multi-stage Dockerfile with Nginx to serve the production build.
6463

6564
```bash
6665
# 1. Build and start the container
6766
docker compose up --build
68-
69-
# 2. Access the application
70-
# Open http://localhost:8080
71-
7267
```
7368

74-
### Option B: Local Development
75-
76-
To run the application using the local Node.js environment:
77-
78-
```bash
79-
yarn install
80-
yarn dev
81-
```
69+
**2. Access the application at: [http://localhost:8080](http://localhost:8080)**
8270

8371
### Stopping Docker Containers
8472

src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { BrowserRouter } from "react-router-dom";
66

77
ReactDOM.createRoot(document.getElementById("root")!).render(
88
<React.StrictMode>
9-
<BrowserRouter basename="/test-abb">
9+
<BrowserRouter basename={import.meta.env.BASE_URL}>
1010
<App />
1111
</BrowserRouter>
1212
</React.StrictMode>

vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ import react from '@vitejs/plugin-react'
44
// https://vitejs.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7-
base: "/test-abb/",
7+
// Use /test-abb/ for GitHub Pages, / for local development
8+
base: process.env.VITE_BASE_PATH || "/",
89
})

0 commit comments

Comments
 (0)