evanw / evanw/esbuild

Re-introduce file splitting optimization

Open
#3,531 6 comments 16 reactions 0 assignees View on GitHub
suboptimal-output
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Code motion/splitting does not seem to work as expected and in some cases this causes non optimal chunks to be created.

Example:

entry-one.js
```js
export {foo2} from './file3.js'
```

entry-two.js
```js
export {foo} from './file3.js'
```

file3.js
```js
export const foo = 'foo';
export const foo2 = 'foo2';
```

The generated common chunk contains the following:
chunk-QXQWH7T5.js
```js
// file3.js
var foo = "foo";
var foo2 = "foo2";

export {
foo,
foo2
};
```

However, since `foo` and `foo2` are never referenced in the same entry-point, the expected behaviour would be that esbuild generates 2 chunks.

chunk-YYY.js
```js
// file3.js
var foo = "foo";

export {
foo
};
```
chunk-XXX.js

```js
// file3.js
var foo = "foo2";

export {
foo2
};
```

Repro https://esbuild.github.io/try/#YgAwLjE5LjgAewogIGJ1bmRsZTogdHJ1ZSwKICBzcGxpdHRpbmc6IHRydWUsCiAgZm9ybWF0OiAnZXNtJywKICBvdXRkaXI6ICcvJywKfQBlAGVudHJ5LW9uZS5qcwBleHBvcnQge2ZvbzIsIGZvbzN9IGZyb20gJy4vZmlsZTMuanMnAGUAZW50cnktdHdvLmpzAGV4cG9ydCB7Zm9vfSBmcm9tICcuL2ZpbGUzLmpzJwAAZmlsZTMuanMAZXhwb3J0IGNvbnN0IGZvbyA9ICdmb28nOwpleHBvcnQgY29uc3QgZm9vMiA9ICdmb28yJzsKZXhwb3J0IGZ1bmN0aW9uIGZvbzMgKCkge30

Version 0.19.8

Related to https://github.com/angular/angular-cli/issues/26622

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the example with the linked esbuild Try URL and the entry-one.js, entry-two.js, and file3.js inputs. Trace the code-splitting behavior for these re-exported symbols and verify that the completed change produces separate chunks containing only foo or foo2 rather than one shared chunk.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, javascript
Domain
build-system, tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.