Registry / web-framework / vite-plugin-import

vite-plugin-import

JSON →
library0.4.0jsnpmunverified

Component modular import plugin for Vite (v0.4.0, last updated 2021). Converts named imports like `import { Button } from 'antd'` into path-level imports (e.g., `antd/lib/button`) to reduce bundle size, leveraging babel-plugin-import under the hood. Works primarily in build mode by default. Requires Vite 2. Note that tree-shakable libraries (like antd) do not need this plugin, as Vite handles unused code removal. Faster than combining `@rollup/plugin-babel` with babel-plugin-import, but limited to import transformation only.

npm install vite-plugin-import
INSTALL
IMPORT
SIG · VITE-PLUGIN-IMPORT
V
vite-plugin-import
web-frameworkjavascriptv0.4.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

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

default (createImportPlugin)
✓ import createImportPlugin from 'vite-plugin-import'
✗ const createImportPlugin = require('vite-plugin-import')
ESM-only; does not support CommonJS require.
default with named import syntax
✓ import createImportPlugin from 'vite-plugin-import'
✗ import { createImportPlugin } from 'vite-plugin-import'
Package exports a default function, not a named export.
createImportPlugin via CJS dynamic import
✓ const { default: createImportPlugin } = await import('vite-plugin-import')
✗ const createImportPlugin = require('vite-plugin-import')
In CommonJS context, use dynamic import and destructure default.

Shows how to configure vite-plugin-import to transform antd imports. The plugin converts named imports to path-level imports and optionally injects style imports.

// vite.config.js import createImportPlugin from 'vite-plugin-import'; export default { plugins: [ createImportPlugin([ { libraryName: 'antd', style: true, // or 'css' }, ]), ], };
Debug
Known issues
gotchaPlugin only works effectively in build mode by default (onlyBuild: true). During dev (vite serve), imports are not transformed, which may lead to inconsistency if you rely on side-effects from style imports.
fix
Set `onlyBuild: false` in plugin options to enable transformation in both dev and build modes.
affects: >=0.0.0
gotchavite-plugin-import is essentially a wrapper around babel + babel-plugin-import. It does not support other babel plugins; use @rollup/plugin-babel if you need additional babel transforms.
fix
Use @rollup/plugin-babel + babel-plugin-import instead for custom babel configuration.
affects: >=0.0.0
gotchaTree-shakable libraries (e.g., antd v4+) do not benefit from this plugin because Vite already eliminates unused exports during build. Unnecessary transformation may even increase build time.
fix
Omit the plugin for tree-shakable libraries; verify with a bundle analyzer.
affects: >=0.0.0
breakingRequires Vite 2; incompatible with Vite 3+.
fix
Stay on Vite 2 or switch to alternative (e.g., unplugin-auto-import or manual imports).
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'vite-plugin-import'
Package not installed or missing from dependencies.
fix
Run `npm install vite-plugin-import --save-dev`.
TypeError: createImportPlugin is not a function
Importing as named export instead of default export.
fix
Use `import createImportPlugin from 'vite-plugin-import'` (no curly braces).
Error: The node module 'vite' is not a peer dependency of 'vite-plugin-import'.
Missing Vite peer dependency.
fix
Install Vite 2.x: `npm install vite@2`.
Error: Cannot find module 'babel-plugin-import'
vite-plugin-import uses babel internally; if babel-plugin-import is missing, this error may appear.
fix
Install babel-plugin-import: `npm install babel-plugin-import --save-dev`.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
viterequiredPeer dependency; requires Vite 2.x
Agent activity
12 hits · last 30 days
node
8
OpenAI (training)
1
Resources