npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

next-export-optimize-svg-images

v1.0.0

Published

Optimize images and SVGs for Next.js static exports with responsive breakpoints and automatic format conversion.

Readme

next-export-optimize-svg-images

A standalone package to optimize images for Next.js static exports, with specialized SVG support.

Features

  • Static Export Friendly: Works with next export by pre-optimizing images during build.
  • Multiple Formats: Generates WebP and AVIF variants.
  • Responsive Breakpoints: Automatically creates resized versions based on configurable breakpoints.
  • SVG Optimization: Uses SVGO for cleaning up SVGs.
  • Custom React Component: <ExportImage /> automatically picks the best variant.

Installation

npm install next-export-optimize-svg-images

Usage

1. Update Scripts

Add the optimization command to your package.json:

"scripts": {
  "build": "next build",
  "postbuild": "next-export-optimize-svg-images"
}

2. Use the Component

The <ExportImage /> component now automatically picks up the manifest generated by the CLI. No manual import or provider is required by default if you use the default output folder (/optimized).

import { ExportImage } from 'next-export-optimize-svg-images';

export default function Page() {
  return (
    <ExportImage 
      src="/assets/images/hero.png" 
      alt="Hero Image"
    />
  );
}

3. Custom Manifest Path (Optional)

If you use a custom outputImageFolderName, you can let the component know where to find the manifest by setting a global variable in your root layout:

// RootLayout.tsx
if (typeof window !== 'undefined') {
  (window as any).__NEXT_EXPORT_OPTIMIZE_SVG_IMAGES_MANIFEST_PATH__ = '/custom-folder/manifest.json';
}

Alternatively, you can still use the ManifestProvider or the manifest prop if you prefer manual control:

import { ManifestProvider } from 'next-export-optimize-svg-images';
import manifest from '../public/optimized/manifest.json';

export default function App({ children }) {
  return (
    <ManifestProvider manifest={manifest}>
      {children}
    </ManifestProvider>
  );
}

Configuration

You can configure the package in three ways:

1. Dedicated Config File

Create a next-export-optimize-svg-images.config.js in your project root:

/** @type {import('next-export-optimize-svg-images').Config} */
module.exports = {
  // Array of widths to generate variants for
  breakpoints: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
  
  // Images not ending in -scale will be capped at this width
  maxNonScaleBreakpoint: 1920,
  
  // Source folder for external/CMS images inside public/
  inputImageFolder: "cms-media",
  
  // Output folder name inside public/
  outputImageFolderName: "optimized",
  
  // Max images to process in parallel
  concurrency: 8,

  features: {
    avif: true,
    webp: true,
    png: false,
    svgHighRes: false, // Force high-res raster fallbacks for SVGs
  },

  // Format-specific settings (Sharp options)
  webp: { quality: 85, effort: 4, lossless: false },
  avif: { quality: 65, effort: 2, chromaSubsampling: "4:2:0" },
  png: { compressionLevel: 9, effort: 10, palette: true },
};

2. Next.js Config Integration

The tool automatically reads from next.config.js (or .mjs, .cjs). It inherits standard Next.js image settings and supports a custom imagesExport key:

// next.config.js
module.exports = {
  output: 'export',
  images: {
    deviceSizes: [640, 750, 828, 1080],
    imageSizes: [16, 32, 48, 64],
    formats: ['image/avif', 'image/webp'],
  },
  // Optional: specialized config for this tool
  imagesExport: {
    maxNonScaleBreakpoint: 2560,
    features: { svgHighRes: true }
  }
};

4. Configuration Options

  • breakpoints: number[] - Array of widths to generate optimized variants for.
  • maxNonScaleBreakpoint: number (default: 1920) - Images WITHOUT -scale in their filename will not be upscaled beyond this width or their original width.
  • inputImageFolder: string (default: "cms-media") - The folder name inside public/ where external/CMS images are stored.
  • outputImageFolderName: string (default: "optimized") - The folder name inside public/ where optimized assets will be placed.
  • concurrency: number - Number of images to process in parallel (defaults to CPU count).
  • features:
    • avif: boolean (default: true) - Enable AVIF generation.
    • webp: boolean (default: true) - Enable WebP generation.
    • png: boolean (default: false) - Enable PNG variant generation.
    • svgHighRes: boolean (default: false) - Force high-resolution raster fallback for SVGs.
  • webp: Object with quality (0-100), effort (0-6), and lossless (boolean).
  • avif: Object with quality (0-100), effort (0-9), and chromaSubsampling (e.g., "4:2:0").
  • png: Object with compressionLevel (0-9), effort (1-10), and palette (boolean).

3. CLI Options

You can override the project root using --root:

next-export-optimize-svg-images --root ./my-project

SVG Support

This package has first-class support for SVG optimization and fallback:

  1. SVGO Integration: Automatically cleans up SVGs.
  2. Raster Fallback: Generates WebP/AVIF versions of SVGs for better performance in some contexts, but defaults to the original SVG if the raster is larger.
  3. High-Res Mode: Force high-resolution raster generation for SVGs even if they exceed the original file size.

License

ISC