esbuild-plugin-cache
raw JSON → 0.2.10 verified Fri May 01 auth: no javascript
An esbuild plugin to cache HTTP/HTTPS imports, enabling bundling of URLs from CDNs like Skypack without npm install or node_modules. Current stable version 0.2.10, released irregularly. Supports import-maps and Deno-style caching (DENO_DIR). Differentiates from Snowpack's Streaming NPM Imports by integrating directly with esbuild, and works in both Node.js and Deno.
Common errors
error Error: Cannot find module 'esbuild-plugin-cache' ↓
cause Package not installed or not found.
fix
Run 'npm install esbuild-plugin-cache' or 'deno add esbuild-plugin-cache'.
error TypeError: cache is not a function ↓
cause Incorrect import style (default import instead of named).
fix
Use 'import { cache } from "esbuild-plugin-cache"'.
error Error: The plugin 'cache' must be passed an object with optional props ↓
cause Calling cache() without arguments or with non-object argument in some versions.
fix
Call cache() with or without options: cache() or cache({}) or cache({importmap, directory}).
Warnings
gotcha The plugin caches HTTP responses in a directory. Ensure the cache directory is writable and has enough space. ↓
fix Set directory option or ensure DENO_DIR environment variable points to a writable path.
breaking Package is ESM-only; does not support CommonJS require(). ↓
fix Use import syntax or ensure project is configured for ESM.
deprecated Version 0.2.1 introduced importmap config; earlier versions had different API. ↓
fix Upgrade to >=0.2.1 and use the importmap option as shown in README.
gotcha The directory option is relative to the current working directory, not the esbuild config. ↓
fix Use absolute paths if needed.
gotcha HTTPS imports are cached indefinitely; no TTL or cache invalidation built-in. ↓
fix Manually clear the cache directory to force re-fetch.
Install
npm install esbuild-plugin-cache yarn add esbuild-plugin-cache pnpm add esbuild-plugin-cache Imports
- cache wrong
const cache = require('esbuild-plugin-cache')correctimport { cache } from 'esbuild-plugin-cache' - cache wrong
import cache from 'esbuild-plugin-cache'correctimport { cache } from 'esbuild-plugin-cache' - type CacheConfig
import type { CacheConfig } from 'esbuild-plugin-cache'
Quickstart
import esbuild from 'esbuild';
import { cache } from 'esbuild-plugin-cache';
const importmap = {
imports: {
react: 'https://cdn.skypack.dev/react@17.0.1',
},
};
await esbuild.build({
entryPoints: ['index.js'],
bundle: true,
outfile: 'bundle.js',
plugins: [cache({ importmap, directory: './cache' })],
});
console.log('Bundled successfully');