# --- Build Stage ---
FROM node:20 AS build
WORKDIR /app

# 1. Nur package.json zuerst kopieren → Cache für Dependencies
COPY package*.json ./

# 2. Abhängigkeiten installieren
RUN npm ci

# 3. Restlichen Code kopieren
COPY . .

# 4. Sicherstellen, dass vite ausführbar ist (Windows-Berechtigungsfix)
RUN chmod +x node_modules/.bin/vite

# 5. Frontend bauen
RUN npm run build

# --- Serve Stage ---
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 3000
CMD ["nginx", "-g", "daemon off;"]
