Skip to main content
A Rollup plugin that enables importing ESM modules from CDN URLs for local processing, allowing tree-shaking on non-local resources.

Features

  • CDN Imports - Import npm packages directly from CDN URLs
  • Tree-shaking - Full tree-shaking support for CDN modules
  • Multiple CDNs - Support for Skypack with fallback chains
  • Version Pinning - Pin specific package versions
  • Custom Resolvers - Use any CDN with custom URL resolvers

Installation

Quick Start

Now you can import packages directly from URLs:

Configuration

Version Pinning

Pin specific versions for reproducible builds:

Custom CDN Resolvers

Use any CDN by providing custom resolver functions:

Custom Fetch Implementation

For environments without global fetch or for adding custom headers:

How It Works

  1. Resolution: When Rollup encounters an import, the plugin checks if it’s a CDN-resolvable module
  2. Fetching: The module is fetched from the configured CDN(s)
  3. Transformation: Relative imports within the fetched module are resolved to absolute CDN URLs
  4. Bundling: Rollup processes the module like any local file, enabling tree-shaking

Import Resolution

API Reference

importCdn(options?)

Creates the Rollup plugin.

Options

Examples

Vite Configuration

Multi-CDN Fallback

Types

Compatibility

  • Rollup: 3.x, 4.x
  • Node.js: 18+ (requires fetch or custom fetchImpl)