Vite plugin that externalizes specified npm packages and loads them from a CDN (jsDelivr, unpkg, cdnjs) in production builds. v1.0.1 supports Vite 2–5, TypeScript types, custom script/link tag generation, presets for react, vue, lodash, etc., and development mode. Unlike generic external plugins (e.g., vite-plugin-externals), it automatically injects CDN script/link tags and offers built-in presets for common libraries. Releases are infrequent; v1.0.0 introduced breaking changes to the options API.
npm install vite-plugin-cdn-importVerified import paths — ran on the pinned version, not inferred.
Configures Vite to externalize react and react-dom to CDN, showing custom module definition and prodUrl override.
Remove autoComplete; add the package name (e.g., 'react') directly to the modules array.
If using Vite 4 or earlier, stick with v0.x. Update modules manually for any removed presets.
Add 'enableInDevMode: true' to your plugin options if you need CDN scripts in dev.
Define a Module object with name, var, path (and optional css) for any package not in the preset list.
Set the 'prodUrl' option to your desired CDN URL template (e.g., 'https://unpkg.com/{name}@{version}/{path}').Use 'import cdn from 'vite-plugin-cdn-import'' and ensure vite.config.ts is treated as ESM (set type: module in package.json or rename .mjs).
Run 'npm install vite-plugin-cdn-import --save-dev' and verify it appears in devDependencies.
Ensure the package name and 'var' (e.g., 'React') are correct and the module is included in options.modules.
Pass a 'modules' array to the plugin, e.g., cdn({ modules: ['react'] }).No dependency data recorded yet.