vite-plugin-barrel

raw JSON →
0.4.1 verified Mon Apr 27 auth: no javascript

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.

error Error: The swc_plugin_barrel package is not compatible with the current @swc/core version.
cause Mismatched @swc/core version installed.
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).
error TypeError: barrel is not a function
cause Default import instead of named import.
fix
Use import { barrel } from 'vite-plugin-barrel'.
error Cannot find module 'vite-plugin-barrel' or its corresponding type declarations.
cause Missing package or incorrect installation.
fix
Run pnpm add vite-plugin-barrel and ensure tsconfig includes types.
breaking 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.
fix Pin @swc/core to match plugin version range as documented.
gotcha 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'.
fix Follow the integration example in README, passing swc_plugin_barrel to react's plugins array.
gotcha Only works with named imports from barrel packages; default imports or deep imports may not be optimized.
fix Use named imports like import { Button } from '@mui/material' instead of import Mui from '@mui/material'.
gotcha The cache root defaults to node_modules/.cache; ensure this path is writable.
fix If cache issues, set cacheRoot option explicitly.
npm install vite-plugin-barrel
yarn add vite-plugin-barrel
pnpm add vite-plugin-barrel

Configures vite-plugin-barrel to optimize imports from @mui/material and @mui/icons-material, improving build performance by 50%+.

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { barrel } from 'vite-plugin-barrel';

export default defineConfig({
  plugins: [
    react(),
    barrel({
      packages: ['@mui/material', '@mui/icons-material'],
    }),
  ],
});