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 🧡

12 reposts86 likes

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'; ```

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

Looking exactly for the same, as I suffer from barrel pattern on some big projects with files exporting lots of things with many of them not being imported in the tests.