Split independent chunks by entrypoint name in bundle (preserve module hierarchy)
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Loving `esbuild`! Thanks for all the hard work pushing this forward.
I have a [project](https://github.com/manzt/numcodecs.js) with several tree-shakeable submodules and a top-level `index.ts` that simply export these default modules by name. Bundling with multiple entrypoints (and `--splitting`), I would expect the module hierarchy to be preserved using the named entrypoints, rather than producing unique chunks that are imported independently by each entrypoint. As an example,
```javascript
// index.ts
export { default as add } from './add';
export { default as subtract } from './subtract';
// add.ts
import { log } from './shared';
export default (a: number, b: number): number => {
log();
return a + b;
}
// subtract.ts
import { log } from './shared';
export default (a: number, b: number): number => {
log();
return a - b;
}
// shared.ts
export const log = () => console.log('I'm shared code!');
```
```bash
esbuild --bundle --format=esm --splitting --outdir=dist index.ts add.ts subtract.ts
dist
├── add.js
├── chunk.LP5ZINJT.js
├── chunk.MWAHXVAE.js
├── chunk.NDHDC5HE.js
├── index.js
└── subtract.js
```
Where each entrypoint imports a unique combination of chunks, and `index.js` does not import `add.js` or `subtract.js`. I would instead expect something like Rollup produces (or what `esbuild` produces when entrypoints aren't within a hierarchy):
```
dist
├── add.js
├── chunk.LP5ZINJE.js
├── index.js
└── subtract.js
```
which reduces the number of chunks and preserves the structure of imports. Instead `index.js` would look something like:
```javascript
import { add_default } from './add.js'; // unique chunk for add.js is bundled into this entrypoint
import { subtract_default } from './subtract.js'; // unique chunk for subtract.js is bundled into this entrypoint
import './chunk.LP5ZINJE.js';
export {
add_default as add,
subtract_default as subtract
}
```
I don't _think_ this is related to #399, and couldn't find another related issue. Apologies if I've missed something!
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the issue with index.ts, add.ts, subtract.ts, and shared.ts using the shown esbuild command. Inspect the generated entrypoint and chunk files, then compare the output with the requested hierarchy-preserving structure. Done means independent chunks are reduced and index.js imports or incorporates the named entrypoint modules as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100