Barrel files

Optimize barrel files by rewriting to direct imports (debarrel)

Overview

Barrel files (e.g., index.ts) re‑export from multiple modules for ergonomic imports. They can hurt tree‑shaking and create cycles. Debarrel rewrites imports that target a barrel file into direct imports from source files at build time (best for dev/test speed and tree‑shaking)

Debarrel

Rewrites import { X } from "./components" to import { X } from "./components/X" (based on re‑exports) during transform.

Enable via Packem config (built-in):

import { defineConfig } from "@visulima/packem/config";

export default defineConfig({
  rollup: {
    debarrel: {
      // include: [/\.([cm]?tsx?|jsx)$/],
      // possibleBarrelFiles: [/index\.(t|j)sx?$/],
    },
  },
});

Notes:

  • Targets TS/JS and JSX variants; you can further scope via include
  • Works purely at build time; no runtime overhead

Tests

See integration tests under packages/packem/__tests__/intigration:

  • barrel.test.ts (general barrel usage)
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues