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-importVerified import paths — ran on the pinned version, not inferred.
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.
Set `onlyBuild: false` in plugin options to enable transformation in both dev and build modes.
Use @rollup/plugin-babel + babel-plugin-import instead for custom babel configuration.
Omit the plugin for tree-shakable libraries; verify with a bundle analyzer.
Stay on Vite 2 or switch to alternative (e.g., unplugin-auto-import or manual imports).
Run `npm install vite-plugin-import --save-dev`.
Use `import createImportPlugin from 'vite-plugin-import'` (no curly braces).
Install Vite 2.x: `npm install vite@2`.
Install babel-plugin-import: `npm install babel-plugin-import --save-dev`.