rules_esbuild icon indicating copy to clipboard operation
rules_esbuild copied to clipboard

[Bug]: rules_esbuild does not tree-shake using `sideEffects` in `package.json`

Open pyrocat101 opened this issue 1 year ago • 0 comments

What happened?

Libraries such as lodash-es relies on "sideEffects": false field in their package.json to property eliminate (tree-shake) unused utilities in the resulting bundle. But rules_esbuild does not seem to respect this field, resulting in large bundles when lodash-es is a dependency.

Disabling Bazel sandbox plugin does not resolve the issue (although there is a very noticeable performance difference).

See "How to reproduce" section for a minimal repro.

Version

Development (host) and target OS/architectures:

Output of bazel --version: aspect 5.8.19

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file: rules_esbuild 0.18.0, rules_js 1.37.0

Language(s) and/or frameworks involved:

How to reproduce

Repro: https://github.com/pyrocat101/esbuild_side_effects_repro

# Produces a large bundle file, where every operator in lodash-es is included in the resulting bundle.
bazel build //:bundle
# Produces a small bundle where only the implementation of used utility is included.
pnpm install
npx esbuild --bundle --format=esm --target=node18 index.js

Any other information?

No response

pyrocat101 avatar Feb 05 '24 02:02 pyrocat101