Registry / web-framework / vite-plugin-cdn2

vite-plugin-cdn2

JSON →
library1.1.0jsnpmunverified

A Vite plugin that replaces imported modules with CDN-hosted scripts and links during build. Current stable version is 1.1.0 (released 2024). Lightweight alternative to vite-plugin-cdn-import with TypeScript types, supports custom CDN resolvers, and works with Vue/JSX/TS. Actively maintained with frequent patch releases.

npm install vite-plugin-cdn2
INSTALL
IMPORT
SIG · VITE-PLUGIN-CDN2
V
vite-plugin-cdn2
web-frameworkjavascriptv1.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cdn
import { cdn } from 'vite-plugin-cdn2'
const cdn = require('vite-plugin-cdn2')
ESM-only; CommonJS require will fail.
default
import { cdn } from 'vite-plugin-cdn2'
import cdn from 'vite-plugin-cdn2'
No default export; only named export 'cdn'.
type IModule
import type { IModule } from 'vite-plugin-cdn2'
import { IModule } from 'vite-plugin-cdn2'
IModule is a type; use 'import type' to avoid runtime inclusion.

Shows how to replace Vue and React modules with CDN links in Vite config.

// vite.config.ts import { defineConfig } from 'vite'; import { cdn } from 'vite-plugin-cdn2'; export default defineConfig({ plugins: [ cdn({ modules: [ { name: 'vue', var: 'Vue', path: 'https://unpkg.com/vue@3/dist/vue.global.prod.js' }, 'react' ] }) ] });
Debug
Known issues
breakingPlugin renamed from 'vite-plugin-cdn' to 'vite-plugin-cdn2'. Old package is deprecated.
fix
Use 'vite-plugin-cdn2' package and update imports.
affects: >=1.0.0
gotchaPlugin only applies during build by default (apply: 'build'). Does not work in dev mode.
fix
Set 'apply: 'serve'' to use during development if needed.
affects: >=1.0.0
deprecatedThe 'external' plugin option exposed in v0.13.0 is deprecated in v1.0.0+ and will be removed.
fix
Use the 'cdn' plugin with 'modules' option instead.
affects: >=1.0.0 <2.0.0
gotchaModule resolution fails in monorepo setups if the module's package.json is not hoisted.
fix
Upgrade to >=0.13.0 which includes fix for monorepo.
affects: <0.13.0
breakingStarting from v1.0.0, the plugin is ESM-only. CJS projects cannot import it.
fix
Switch project to ESM or use dynamic import().
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'vite-plugin-cdn2'
Package not installed or typo (missing '2').
fix
Run 'npm install vite-plugin-cdn2 -D' and import correctly.
TypeError: cdn is not a function
Default import used instead of named import.
fix
Use 'import { cdn } from 'vite-plugin-cdn2''.
Uncaught SyntaxError: The requested module 'vite-plugin-cdn2' does not provide an export named 'default'
Default import used when only named export exists.
fix
Change import to named: 'import { cdn } from ...'.
Error: [vite] Internal server error: Cannot read properties of undefined (reading 'transform')
Plugin applied incorrectly (likely missing 'apply' or placed after Vite built-in plugins).
fix
Ensure plugin is placed before built-in plugins and 'apply' is set correctly.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
viterequiredThis is a Vite plugin; requires Vite as a peer dependency.
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
vite-plugin-cdn2 — npm install vite-plugin-cdn2 · libregistry