evanw / evanw/esbuild

splitting with multiple entrypoints does not split dependencies into smaller more optimal chunks

Open
#2,227 1 comment 4 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I have multiple entrypoints that import from some set of library modules, and I would like to use splitting to spit out "optimal" chunks such that each entrypoint only ends up importing the subset of library modules it needs.

[Here's an example with esbuild](https://hyrious.me/esbuild-repl/?version=0.14.10&mode=build&modules=%5B%5B%22comp1.js%22%2C%22let+count+%3D+0%3B%5Cnexport+default+function+Comp1%28%29+%7B%5Cn%5Ctcount+%2B%3D+1%3B%5Cn%5Ctreturn+%60Comp1+%24%7Bcount%7D%60%3B%5Cn%7D%22%2C0%5D%2C%5B%22comp2.js%22%2C%22let+count+%3D+0%3B%5Cnexport+default+function+Comp2%28%29+%7B%5Cn%5Ctcount+%2B%3D+1%3B%5Cn%5Ctreturn+%60Comp2+%24%7Bcount%7D%60%3B%5Cn%7D%22%2C0%5D%2C%5B%22comps.js%22%2C%22import+Comp1+from+%5C%22.%2Fcomp1%5C%22%3B%5Cnimport+Comp2+from+%5C%22.%2Fcomp2%5C%22%3B%5Cnexport+%7BComp1%2C+Comp2%7D%3B%22%2C0%5D%2C%5B%22main1.js%22%2C%22import+%7BComp1%7D+from+%5C%22.%2Fcomps%5C%22%3B%5Cnconsole.log%28Comp1%29%3B%22%2C1%5D%2C%5B%22main2.js%22%2C%22import+%7BComp2%7D+from+%5C%22.%2Fcomps%5C%22%3B%5Cnconsole.log%28Comp2%29%3B%22%2C1%5D%2C%5B%22main3.js%22%2C%22import+%7BComp1%7D+from+%5C%22.%2Fcomps%5C%22%3B%5Cnconsole.log%28Comp1%29%3B%22%2C1%5D%2C%5B%22main4.js%22%2C%22import+%7BComp2%7D+from+%5C%22.%2Fcomps%5C%22%3B%5Cnconsole.log%28Comp2%29%3B%22%2C1%5D%5D&buildOptions=%7B%22bundle%22%3Atrue%2C%22splitting%22%3Atrue%2C%22format%22%3A%22esm%22%7D), where the result is not optimal; each entrypoint (main*.js) ends up importing all the library module code (Comp1 / Comp2), even though each only needs either Comp1 or Comp2.

Rollup does split this more optimally; [here's the rollup output](https://rollupjs.org/repl/?version=2.71.1&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMCU3QkNvbXAxJTdEJTIwZnJvbSUyMCU1QyUyMi4lMkZjb21wcyU1QyUyMiUzQiU1Q25jb25zb2xlLmxvZyhDb21wMSklM0IlMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSU3RCUyQyU3QiUyMm5hbWUlMjIlM0ElMjJtYWluMi5qcyUyMiUyQyUyMmNvZGUlMjIlM0ElMjJpbXBvcnQlMjAlN0JDb21wMiU3RCUyMGZyb20lMjAlNUMlMjIuJTJGY29tcHMlNUMlMjIlM0IlNUNuY29uc29sZS5sb2coQ29tcDIpJTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlN0QlMkMlN0IlMjJuYW1lJTIyJTNBJTIyY29tcDEuanMlMjIlMkMlMjJjb2RlJTIyJTNBJTIybGV0JTIwY291bnQlMjAlM0QlMjAwJTNCJTVDbmV4cG9ydCUyMGRlZmF1bHQlMjBmdW5jdGlvbiUyMENvbXAxKCklMjAlN0IlNUNuJTVDdGNvdW50JTIwJTJCJTNEJTIwMSUzQiU1Q24lNUN0cmV0dXJuJTIwJTYwQ29tcDElMjAlMjQlN0Jjb3VudCU3RCU2MCUzQiU1Q24lN0QlMjIlMkMlMjJpc0VudHJ5JTIyJTNBZmFsc2UlN0QlMkMlN0IlMjJuYW1lJTIyJTNBJTIyY29tcDIuanMlMjIlMkMlMjJjb2RlJTIyJTNBJTIybGV0JTIwY291bnQlMjAlM0QlMjAwJTNCJTVDbmV4cG9ydCUyMGRlZmF1bHQlMjBmdW5jdGlvbiUyMENvbXAyKCklMjAlN0IlNUNuJTVDd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TdCJTdEJTdEJTJDJTIyZXhhbXBsZSUyMiUzQW51bGwlN0Q=).

Is it possible to achieve a result like rollup's with esbuild?

Thanks!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the linked esbuild example with multiple JavaScript entrypoints and compare its chunks with the linked Rollup output. Done means splitting produces smaller entrypoint-specific chunks so each main*.js includes only the library modules it uses; no implementation files or tests are named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, javascript
Domain
build-system, tooling
Issue type
Feature
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.