BU

bundle-barrel-imports

Switch to direct imports to reduce bundle size and speed up development.

Install

mkdir -p .claude/skills/bundle-barrel-imports && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/4649" && unzip -o skill.zip -d .claude/skills/bundle-barrel-imports && rm skill.zip

Installs to .claude/skills/bundle-barrel-imports

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Import directly from source files instead of barrel files. Apply when using libraries like lucide-react, @mui/material, or @radix-ui/react-* to reduce bundle size and improve dev boot time.
189 chars✓ has a “when” trigger
Intermediate

Key capabilities

  • Identify barrel file imports in source code
  • Replace barrel imports with direct source file imports
  • Optimize bundle size for component libraries
  • Improve development boot time and HMR speed

How it works

The skill identifies entry points that re-export multiple modules and replaces them with specific imports to prevent the bundler from loading unused library code.

Inputs & outputs

You give it
Codebase containing barrel file imports
You get back
Codebase refactored to use direct source imports

When to use bundle-barrel-imports

  • Reduce bundle size for large component libraries
  • Speed up development boot time
  • Optimize production cold starts

About this skill

Avoid Barrel File Imports

Import directly from source files instead of barrel files to avoid loading thousands of unused modules. Barrel files are entry points that re-export multiple modules (e.g., index.js that does export * from './module').

Popular icon and component libraries can have up to 10,000 re-exports in their entry file. For many React packages, it takes 200-800ms just to import them, affecting both development speed and production cold starts.

Why tree-shaking doesn't help: When a library is marked as external (not bundled), the bundler can't optimize it. If you bundle it to enable tree-shaking, builds become substantially slower analyzing the entire module graph.

Incorrect (imports entire library):

import { Check, X, Menu } from 'lucide-react'
// Loads 1,583 modules, takes ~2.8s extra in dev
// Runtime cost: 200-800ms on every cold start

import { Button, TextField } from '@mui/material'
// Loads 2,225 modules, takes ~4.2s extra in dev

Correct (imports only what you need):

import Check from 'lucide-react/dist/esm/icons/check'
import X from 'lucide-react/dist/esm/icons/x'
import Menu from 'lucide-react/dist/esm/icons/menu'
// Loads only 3 modules (~2KB vs ~1MB)

import Button from '@mui/material/Button'
import TextField from '@mui/material/TextField'
// Loads only what you use

Alternative (Next.js 13.5+):

// next.config.js - use optimizePackageImports
module.exports = {
  experimental: {
    optimizePackageImports: ['lucide-react', '@mui/material']
  }
}

// Then you can keep the ergonomic barrel imports:
import { Check, X, Menu } from 'lucide-react'
// Automatically transformed to direct imports at build time

Direct imports provide 15-70% faster dev boot, 28% faster builds, 40% faster cold starts, and significantly faster HMR.

Libraries commonly affected: lucide-react, @mui/material, @mui/icons-material, @tabler/icons-react, react-icons, @headlessui/react, @radix-ui/react-*, lodash, ramda, date-fns, rxjs, react-use.

Reference: How we optimized package imports in Next.js

When not to use it

  • Small projects where bundle size is not a concern
  • Libraries that do not support direct file imports

Limitations

  • Requires manual verification of library import paths
  • May require configuration changes in build tools

How it compares

It optimizes performance by bypassing the overhead of large barrel files, which generic tree-shaking often fails to mitigate.

Compared to similar skills

bundle-barrel-imports side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
bundle-barrel-imports (this skill)16moNo flagsIntermediate
nextjs-developer3282moNo flagsAdvanced
frontend-developer274moNo flagsIntermediate
nextjs-app-router-patterns32moNo flagsAdvanced

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

nextjs-developer

zenobi-us

Expert Next.js developer mastering Next.js 14+ with App Router and full-stack features. Specializes in server components, server actions, performance optimization, and production deployment with focus on building fast, SEO-friendly applications.

328531

frontend-developer

sickn33

Build React components, implement responsive layouts, and handle client-side state management. Masters React 19, Next.js 15, and modern frontend architecture. Optimizes performance and ensures accessibility. Use PROACTIVELY when creating UI components or fixing frontend issues.

2782

nextjs-app-router-patterns

wshobson

Master Next.js 14+ App Router with Server Components, streaming, parallel routes, and advanced data fetching. Use when building Next.js applications, implementing SSR/SSG, or optimizing React Server Components.

347

react-performance

li-lance

Optimize React rendering, bundle size, and data fetching performance. Use when optimizing React rendering performance, reducing re-renders, or improving bundle size. (triggers: **/*.tsx, **/*.jsx, waterfall, bundle, lazy, suspense, dynamic)

00

senior-frontend

FISCFED9

Frontend development skill for React, Next.js, TypeScript, and Tailwind CSS applications. Use when building React components, optimizing Next.js performance, analyzing bundle sizes, scaffolding frontend projects, implementing accessibility, or reviewing frontend code quality.

00

landing-page-guide-v2

bear2u

Create distinctive, high-converting landing pages that combine proven conversion elements with exceptional design quality. Build beautiful, memorable landing pages using Next.js 14+ and ShadCN UI that avoid generic AI aesthetics while following the 11 essential elements framework.

48105

Search skills

Search the agent skills registry