feat: integrate WebP/AVIF image optimization into build pipeline
Build and Deploy / build-and-test (push) Failing after 28s
Build and Deploy / build-image (push) Has been skipped
Build and Deploy / deploy (push) Has been skipped

- Add sharp dependency for image format conversion
- Generate WebP (quality 80) and AVIF (quality 70) variants for all raster images
- Render <picture> elements with srcset fallbacks (AVIF > WebP > original)
- SVG images remain as <img> without picture wrapper
- Update Dockerfile to install libvips for sharp, copy from public/ dir
- Add nginx cache rules for .webp and .avif files
- Add .gitignore for node_modules, public, dist
This commit is contained in:
2026-05-31 16:21:03 +00:00
parent f649fff223
commit 16cad3fe36
15 changed files with 1831 additions and 98 deletions
+7 -4
View File
@@ -3,6 +3,9 @@ FROM node:22-alpine AS builder
WORKDIR /app
# Install build dependencies for sharp (libvips)
RUN apk add --no-cache python3 make g++ vips-dev
# Copy package files and install dependencies
COPY package*.json ./
RUN npm ci
@@ -15,12 +18,12 @@ RUN npm run build
FROM nginx:alpine
# Copy built site
COPY --from=builder /app/dist /usr/share/nginx/html
COPY --from=builder /app/public /usr/share/nginx/html
# Copy ads.txt if present at root
COPY --from=builder /app/ads.txt /usr/share/nginx/html/ads.txt
COPY --from=builder /app/public/ads.txt /usr/share/nginx/html/ads.txt
# Custom nginx config for SPA/history routing
# Custom nginx config for SPA/history routing with image format support
RUN echo 'server { \
listen 80; \
server_name localhost; \
@@ -29,7 +32,7 @@ RUN echo 'server { \
location / { \
try_files $uri $uri/ /index.html; \
} \
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { \
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|webp|avif)$ { \
expires 1y; \
add_header Cache-Control "public, immutable"; \
} \