{"id":22589,"library":"vite-plugin-barrel","title":"vite-plugin-barrel","description":"Vite plugin to optimize barrel (re-export) file imports, improving build performance for packages with many exports like @mui/icons-material. Current stable version is 0.4.1, released monthly. Requires Vite ^5 and Node >=18. Uses SWC under the hood via swc-plugin-barrel; watch out for @swc/core version compatibility. Key differentiator: dedicated barrel-import optimization for Vite, inspired by Next.js optimizePackageImports, with integration support for @vitejs/plugin-react-swc.","status":"active","version":"0.4.1","language":"javascript","source_language":"en","source_url":"https://github.com/JiangWeixian/vite-plugin-barrel","tags":["javascript","typescript"],"install":[{"cmd":"npm install vite-plugin-barrel","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-barrel","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-barrel","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency, required ^5","package":"vite","optional":false}],"imports":[{"note":"Named export, not default.","wrong":"import barrel from 'vite-plugin-barrel'","symbol":"barrel","correct":"import { barrel } from 'vite-plugin-barrel'"},{"note":"ESM only; no CJS distribution.","wrong":"const { swc_plugin_barrel } = require('vite-plugin-barrel')","symbol":"swc_plugin_barrel","correct":"import { swc_plugin_barrel } from 'vite-plugin-barrel'"},{"wrong":null,"symbol":"defineConfig from vite","correct":"import { defineConfig } from 'vite'"}],"quickstart":{"code":"import { defineConfig } from 'vite';\nimport react from '@vitejs/plugin-react';\nimport { barrel } from 'vite-plugin-barrel';\n\nexport default defineConfig({\n  plugins: [\n    react(),\n    barrel({\n      packages: ['@mui/material', '@mui/icons-material'],\n    }),\n  ],\n});","lang":"typescript","description":"Configures vite-plugin-barrel to optimize imports from @mui/material and @mui/icons-material, improving build performance by 50%+."},"warnings":[{"fix":"Pin @swc/core to match plugin version range as documented.","message":"v0.4.x requires @swc/core compatibility with v1.7.0-v1.7.27; v0.2.x-0.3.x requires @swc/core 1.6.x.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Follow the integration example in README, passing swc_plugin_barrel to react's plugins array.","message":"If using @vitejs/plugin-react-swc, the swc_plugin_barrel must be passed to react plugin via its plugins option, and barrel() must be called with experimental.integration: 'plugin-react-swc'.","severity":"gotcha","affected_versions":">=0.2.0"},{"fix":"Use named imports like import { Button } from '@mui/material' instead of import Mui from '@mui/material'.","message":"Only works with named imports from barrel packages; default imports or deep imports may not be optimized.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"If cache issues, set cacheRoot option explicitly.","message":"The cache root defaults to node_modules/.cache; ensure this path is writable.","severity":"gotcha","affected_versions":">=0.4.1"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Check swc_compat_range_docs and install compatible @swc/core (e.g., npm install @swc/core@1.6.7 for v0.2.x-0.3.x).","cause":"Mismatched @swc/core version installed.","error":"Error: The swc_plugin_barrel package is not compatible with the current @swc/core version."},{"fix":"Use import { barrel } from 'vite-plugin-barrel'.","cause":"Default import instead of named import.","error":"TypeError: barrel is not a function"},{"fix":"Run pnpm add vite-plugin-barrel and ensure tsconfig includes types.","cause":"Missing package or incorrect installation.","error":"Cannot find module 'vite-plugin-barrel' or its corresponding type declarations."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}