# Multi-stage build to compile the project from source and serve as a static site
# Stage 1: Build
FROM node:slim as builder
WORKDIR /app
# Install dependencies (copy package.json first for layer caching)
COPY package.json ./
RUN npm install
# Ensure Babel CLI is available for non-watch builds
RUN npm install --save-dev babel-cli
# Copy the rest of the project
COPY . .
# Build from source: transpile and bundle
RUN ./node_modules/.bin/babel src --out-dir dist
RUN ./node_modules/.bin/webpack
# Stage 2: Runtime
FROM node:slim
WORKDIR /app
# Copy build artifacts and static assets from the builder
COPY --from=builder /app/dist /app/dist
COPY --from=builder /app/index.html /app/index.html
COPY --from=builder /app/index.css /app/index.css
COPY --from=builder /app/assets /app/assets
COPY --from=builder /app/examples /app/examples
# Expose a lightweight static server (http-server)
RUN npm install -g http-server
EXPOSE 8080
# Command to serve this directory statically on port 8080
CMD ["http-server", ".", "-p", "8080"]