40 lines
1.0 KiB
Docker
40 lines
1.0 KiB
Docker
# Frontend Dockerfile for Vue/Vite TypeScript project
|
|
FROM node:20-alpine AS base
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package files first for better caching
|
|
COPY frontend/package*.json ./
|
|
COPY frontend/yarn.lock* frontend/pnpm-lock.yaml* ./
|
|
|
|
# Install dependencies
|
|
RUN if [ -f yarn.lock ]; then yarn install; \
|
|
elif [ -f pnpm-lock.yaml ]; then npm install -g pnpm && pnpm install; \
|
|
else npm install; fi
|
|
|
|
# Copy application code
|
|
COPY frontend/ .
|
|
|
|
# Development stage
|
|
FROM base AS development
|
|
EXPOSE 5173
|
|
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]
|
|
|
|
# Production build stage
|
|
FROM base AS build
|
|
RUN if [ -f yarn.lock ]; then yarn build; \
|
|
elif [ -f pnpm-lock.yaml ]; then pnpm build; \
|
|
else npm run build; fi
|
|
|
|
# Production stage
|
|
FROM nginx:alpine AS production
|
|
# Copy built assets from build stage
|
|
COPY --from=build /app/dist /usr/share/nginx/html
|
|
# Copy nginx configuration
|
|
COPY frontend/nginx.conf /etc/nginx/nginx.conf
|
|
# Expose port
|
|
EXPOSE 80
|
|
# Start nginx
|
|
CMD ["nginx", "-g", "daemon off;"]
|