Registry / devops / vite-plugin-importus

vite-plugin-importus

JSON →
library1.0.5jsnpmunverified

Vite plugin for modular import transformation, automatically converting named imports from a library into path-specific imports and optional style imports. Version 1.0.5 requires Vite >=2 and Node >=14. It uses acorn and es-module-lexer for faster transforms (claimed 90% faster than alternatives like vite-plugin-import and vite-plugin-importer). Inspired by babel-plugin-import, it supports the same options. TypeScript types are included. Release cadence is irregular.

npm install vite-plugin-importus
INSTALL
IMPORT
SIG · VITE-PLUGIN-IMPORT
V
vite-plugin-importus
devopsjavascriptv1.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

vitePluginImportus
import vitePluginImportus from 'vite-plugin-importus'
const vitePluginImportus = require('vite-plugin-importus')
Default export; ESM-only. CommonJS require will fail in Vite ESM context.
VitePluginImportusOptions
import type { VitePluginImportusOptions } from 'vite-plugin-importus'
import { VitePluginImportusOptions } from 'vite-plugin-importus'
This is a type export; do not import it as a value.
PluginOption
import { PluginOption } from 'vite'
The plugin returns PluginOption; ensure Vite types are installed.

Configures the plugin in vite.config.ts to transform antd named imports to path-specific imports with CSS.

// vite.config.ts import { defineConfig } from 'vite' import vitePluginImportus from 'vite-plugin-importus' export default defineConfig({ plugins: [ vitePluginImportus([ { libraryName: 'antd', libraryDirectory: 'es', style: 'css', }, ]), ], }) // Then in your app code: import { Button } from 'antd' // Transforms to: import Button from 'antd/es/button' and style imports
Debug
Known issues
gotchaPlugin options array must match library directory structure; incorrect libraryDirectory or style path may cause import errors.
fix
Verify the exact path structure of the library (e.g., 'es' vs 'lib') and style entry (e.g., 'css' vs 'style/css').
affects: >=1.0.0
gotchaPlugin does not support dynamic imports or re-exports; only works with static import statements.
fix
Use static imports for the targeted library, or use a different plugin if you need dynamic import support.
affects: >=1.0.0
gotchaUsing with libraries that have side-effect imports may result in duplicated or missing imports.
fix
Use the 'libraryName' and 'libraryPath' options to fine-tune; check library documentation for correct path.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'vite-plugin-importus' or its corresponding type declarations.
Missing dependency or TypeScript not configured to resolve Vite plugins.
fix
Run 'npm install -D vite-plugin-importus' and ensure 'vite.config.ts' is included in tsconfig.
Transform failed with error: could not resolve import
Incorrect libraryPath or libraryName options cause the plugin to generate unresolvable imports.
fix
Double-check the 'libraryDirectory' (e.g., 'es', 'lib') and ensure the path exists in the node_modules library.
Uncaught TypeError: Cannot read properties of undefined (reading 'transform')
Plugin executed before Vite has resolved peer dependencies.
fix
Ensure Vite >=2 is installed and that the plugin is listed in the plugins array, not nested.
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies
viterequiredpeer dependency; plugin only works with Vite
Agent activity
4 hits · last 30 days
node
4
Resources
vite-plugin-importus — npm install vite-plugin-importus · libregistry