# Build stage: build/minify assets from source
FROM node:18-alpine AS builder
WORKDIR /build
# Copy repository contents into the builder
COPY . .
# Install minimal tooling for asset minification
RUN npm install -g uglify-js clean-css-cli
# Create a dist directory and generate minified assets
RUN mkdir -p dist
RUN uglifyjs jquery.onepage-scroll.js -o dist/jquery.onepage-scroll.min.js
RUN cleancss -o dist/onepage-scroll.min.css onepage-scroll.css
# Create a simple index.html that references the built assets
RUN printf "<!doctype html><html><head><meta charset='utf-8'><title>One Page Scroll</title><link rel='stylesheet' href='dist/onepage-scroll.min.css'></head><body><h1>One Page Scroll</h1><script src='dist/jquery.onepage-scroll.min.js'></script></body></html>" > index.html
# Final stage: serve static assets with nginx
FROM nginx:stable-alpine
# Copy built assets from builder into nginx document root
COPY --from=builder /build /usr/share/nginx/html
# Expose port 80
EXPOSE 80
# Run nginx in the foreground
CMD ["nginx", "-g", "daemon off;"]