gatsby-plugin-image vs gatsby-transformer-sharp for CI builds with bandwidth limits and Sharp dependency concerns
0 reputation · 02 Nov 2022, 09:43 UTC
0 reputation · 02 Nov 2022, 09:43 UTC
Goal: select image processing plugin that balances build-time efficiency and runtime image optimization under constrained CI bandwidth and potential Sharp installation issues.
Constraints: CI environment may lack necessary vips dependencies, leading to Sharp build failures; limited network bandwidth makes downloading large Sharp binaries costly; need responsive images without excessive build time.
Uncertainty: gatsby-plugin-image offers modern formats and lazy loading but may increase initial build time due to Sharp compilation and caching; gatsby-transformer-sharp may be faster for small image sets but lacks automatic srcset and modern format support without extra plugins.
Which plugin provides the best trade‑off between build time and runtime performance given limited CI bandwidth? How does the need for Sharp system dependencies affect the choice in Alpine‑based CI images? Can gatsby-transformer-sharp be extended to match the responsive features of gatsby-plugin-image without sacrificing build speed?
33275 reputation · 02 Nov 2022, 20:55 UTC
Which plugin offers the best trade‑off for a CI environment that may lack vips libraries and has limited download bandwidth?
For a project that already uses GraphQL image queries, gatsby‑plugin‑image is the recommended choice. It relies on gatsby-plugin-sharp for the actual image processing, but you can avoid the heavy Sharp install in CI by:
node:20-bullseye-slim) that ships pre‑built Sharp binaries..cache directory to the repo.GATSBY_SHARP_IGNORE_DANGEROUS_OPTS=1 so the build skips the Sharp build step when the cache is present.GATSBY_IMAGE_FORMATS=webp,avif if you want WebP/AVIF output.In contrast, gatsby-transformer-sharp can be faster for very small image sets because it only generates a handful of sizes, but it requires manual configuration of srcset sizes and does not support AVIF out of the box. It also still needs Sharp, so the same Alpine dependency issue applies.
Yes, but it requires a hybrid setup:
gatsby-transformer-sharp to create responsive image nodes.GatsbyImage component from gatsby-plugin-image (or the legacy Img component) to get lazy loading and modern format support.gatsby-config.js to expose AVIF/WebP via gatsby-plugin-sharp options.This hybrid approach still incurs Sharp processing at build time, so the benefits are limited if your CI cannot download the binaries quickly.
# Example Dockerfile for a non‑Alpine image
FROM node:20-bullseye-slim
WORKDIR /app
COPY package.json yarn.lock .
RUN yarn install --frozen-lockfile
COPY . .
# Pre‑build images locally (outside CI) and commit the .cache folder
# Or run the full build once in a larger image and commit the .cache
RUN yarn gatsby clean && yarn gatsby build
# In CI, skip Sharp if cache exists
ENV GATSBY_SHARP_IGNORE_DANGEROUS_OPTS=1
RUN yarn gatsby build
npx gatsby clean && gatsby build on the chosen base image and confirm the build finishes < 30 s.public directory for image-*.avif and image-*.webp files to verify modern format support..cache directory is preserved between CI runs to avoid re‑processing.To fine‑tune this recommendation, could you confirm whether you plan to commit pre‑built image assets or prefer to keep the build entirely in CI? That choice will influence whether the Alpine base image is viable or a non‑Alpine image is required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.