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

emdash-plugin-modern-images

v1.3.0

Published

Converts images to modern formats (WebP, AVIF) with responsive srcset, disk caching, and LCP preload support

Readme

emdash-plugin-modern-images

CI npm version

Adds responsive WebP/AVIF delivery for EmDash media images with a <picture> component, on-demand Sharp conversion, disk caching, and LCP preload support.

Quick start

npm install emdash-plugin-modern-images
npx emdash-plugin-modern-images

The CLI creates src/middleware.ts and prints the config snippet for registering the plugin.

Manual setup

1. Register the plugin

Add to astro.config.mjs:

import { modernImagesPlugin } from "emdash-plugin-modern-images";

export default defineConfig({
  integrations: [
    emdash({
      plugins: [modernImagesPlugin()],
    }),
  ],
});

The plugin registration adds the admin settings page. Optimized image delivery is handled by the Astro middleware in step 3.

2. Use <ModernImage> in your templates

---
import ModernImage from "emdash-plugin-modern-images/astro/ModernImage";
---

<ModernImage image={post.data.featured_image} />

<!-- With custom sizes and LCP preload -->
<ModernImage image={post.data.featured_image} sizes="(min-width: 768px) 50vw, 100vw" preload />

The component renders a <picture> with AVIF and WebP sources. The browser picks the best format. The original image is the fallback. Widths are clamped to 16-2400, quality is clamped to 30-95, and media storage keys are URL-encoded before being used in generated URLs.

3. Enable optimized delivery

Create src/middleware.ts:

export { onRequest } from "emdash-plugin-modern-images/astro/middleware";

This intercepts /_emdash/api/media/file/...?format=...&w=...&q=... requests and serves cached WebP/AVIF/JPEG variants. On cache miss, it converts the original image with Sharp and stores the result under .cache/images inside UPLOADS_DIR by default.

If you already have middleware, compose:

import { sequence } from "astro:middleware";
import { onRequest as modernImages } from "emdash-plugin-modern-images/astro/middleware";

export const onRequest = sequence(yourMiddleware, modernImages);

Props

| Prop | Type | Default | Description | |---|---|---|---| | image | { id?, src?, alt?, meta? } | required | EmDash image field. Uses meta.storageKey or id for the URL, falls back to extracting from src. | | widths | number[] | [480, 640, 960, 1200] | Responsive widths for srcset | | sizes | string | "100vw" | HTML sizes attribute | | loading | "lazy" \| "eager" | "lazy" | Native lazy loading | | decoding | "async" \| "sync" \| "auto" | "async" | Image decoding hint | | class | string | — | CSS class forwarded to <img> | | preload | boolean | false | Emit <link rel="preload"> for LCP optimization | | formatQuality | number | 78 | Output quality for generated URLs, clamped to 30–95 |

External URLs (http:// / https://) are rendered as a plain <img> without optimization.

Runtime model

modernImagesPlugin() is a standard EmDash plugin. Its sandbox/runtime entrypoint only stores admin settings in plugin KV and does not read media files or run Sharp.

Image conversion happens in the exported Astro middleware, which runs in the host Astro app and uses Node APIs. This keeps the plugin descriptor compatible with EmDash standard plugin boundaries while still allowing local filesystem caching for optimized media delivery.

Environment variables

| Variable | Default | Description | |---|---|---| | UPLOADS_DIR | ./uploads | Directory where EmDash media files are stored | | IMAGE_CACHE_DIR | ${UPLOADS_DIR}/.cache/images | Directory for generated image variants |

Admin Settings

Navigate to /_emdash/adminModern Images.

The admin page stores plugin settings in EmDash plugin KV. In the current implementation, generated image URLs are controlled by <ModernImage> props and the middleware request parameters; the middleware does not read plugin KV.

| Field | Default | Description | |---|---|---| | Default format | webp | Stored preference. <ModernImage> currently emits AVIF first, then WebP. | | Quality | 78 | Stored preference. Use the formatQuality prop to control generated URLs. |

Development

git clone https://github.com/adrianoamalfi/emdash-plugin-modern-images.git
cd emdash-plugin-modern-images
npm install
npm run typecheck
npm test

License

MIT © Adriano Amalfi