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

@foony/vite-plugin-import-map

v1.0.0

Published

Vite plugin that generates import maps to prevent cascading hash changes. Created by foony.com

Downloads

33

Readme

vite-plugin-import-map

A Vite plugin that generates import maps to prevent cascading hash changes in production builds.

Created by foony.com - Play free online games.

Problem

When using content-based hashing for production builds, changing a single file can cause many other files to get new hashes, even though their actual content hasn't changed. This happens because files import each other using hashed filenames like ./button-abc12345.js. When button.tsx changes and becomes button-def45678.js, all files that import it also change because they contain the old filename string.

This cascading effect causes:

  • Unnecessary cache invalidation
  • Difficulty tracking what actually changed between builds
  • Build failures when hitting file limits (e.g., Cloudflare Pages' 20,000 file limit)

Solution

This plugin uses Import Maps to decouple module specifiers from file paths. Instead of importing "./button-abc123.js", files import "button". The browser uses the import map to resolve "button" to the actual hashed filename.

This means:

  • File content stays identical (always imports "button"), so hashes stay the same
  • Only the import map and changed files get new hashes
  • No cascading hash changes

For a detailed explanation of the problem and solution, see How I Solved Cascading Hash Changes with Import Maps.

Installation

npm install vite-plugin-import-map

Usage

import { defineConfig } from 'vite';
import importMapPlugin from 'vite-plugin-import-map';

export default defineConfig({
  plugins: [
    importMapPlugin({
      assetsDir: 'assets', // optional, defaults to 'assets'
      useAbsolutePaths: true, // optional, defaults to true
    }),
  ],
});

Configuration

assetsDir?: string

The directory where assets are stored. Defaults to 'assets'. If not provided, the plugin will read this from Vite's build.assetsDir configuration.

useAbsolutePaths?: boolean

Whether to use absolute paths (starting with /) or relative paths (starting with ./) in the import map.

  • true (default): Absolute paths like /assets/index-abc123.js. Required for SSG where HTML files are served from subdirectories.
  • false: Relative paths like ./assets/index-abc123.js. Preferred for HTML5 builds that may not be served from root.

How It Works

  1. First pass: Counts base names to detect conflicts (multiple chunks with the same name)
  2. Second pass: Builds a mapping from hashed filenames to stable module specifiers
  3. Third pass: Transforms all import statements in chunk code to use stable specifiers, then recomputes hashes
  4. Fourth pass: Renames files with new hashes and updates the import map
  5. HTML injection: Injects the import map as a <script type="importmap"> tag in the HTML head

The plugin uses AST parsing (via Acorn) to safely transform only actual import statements, avoiding false positives from strings that happen to look like filenames.

License

MIT


Created by foony.com - Play free online games.