Post

🚀 Lazy Barrel Optimization in Rolldown Barrel files, files that re-export from other modules, are common in modern JavaScript projects but a nightmare for your build time. Rolldown now has Lazy Barrel Optimization to fix this. Here's how it works 🧵

You often do not use all functions or components from a library, but they are all exported from a single barrel file. ```js // some-lib/index.js export { a } from './a'; export { b } from './b'; // more exports here [...] // main.js import { a } from 'some-lib'; ```

0 reposts6 likes

Without any optimization, your bundler has to traverse the entire barrel file and compile all modules, even the unused ones. But with Lazy Barrel Optimization, Rolldown only includes what you actually use and skips the rest.

Real-world impact with Ant Design as example ```js import { Button } from 'antd'; ``` ◆ Without: 2986 modules, ~65ms ◆ With: 250 modules, ~28ms That's 92% fewer modules and 2-4x faster builds.

Rolldown's Lazy Barrel Optimization supports all the patterns you'd expect: ◆ `export * from './components'` ◆ `export { Component } from './Component'` ◆ `export * as ns from './module'` ◆ Mixed exports ◆ Circular references ◆ Self re-exports

Enabling it is simple. Just add this to your Rolldown config: ```js export default { experimental: { lazyBarrel: true, }, }; ``` For Vite 8, you can put it under `build.rolldownOptions`