denoland / dnt

Deno to npm package build tool.
MIT License
1.25k stars 40 forks source link

Treeshaking of rewritten local dependencies #180

Closed tom-sherman closed 1 year ago

tom-sherman commented 2 years ago

Reproduction:

  1. Checkout https://github.com/tom-sherman/response-multipart/commit/ebbe84ee913c7ff87905134ca774baf1f0fde268
  2. Run deno run --allow-all scripts/build_npm.ts

Actual behaviour:

npm/src/deps/deno.land/std@0.145.0/bytes/mod.ts contains unused exports

Desired behaviour:

Only the used exports should be included


It would be good if dnt tried to treeshake unused exports. It's fine if this is best effort IMO (all treeshaking is best effort anyways I believe)

dsherret commented 2 years ago

It would be a lot of work to do this. What you could do for now is add a post build step that uses a tool that performs tree shaking on the output.

tom-sherman commented 2 years ago

@dsherret Maybe it could be possible to leverage https://github.com/swc-project/swc/tree/main/crates/swc_bundler for figuring out the dependency graph and performing the tree shaking

dsherret commented 1 year ago

This is out of scope for dnt because it's a lot of work. I'd recommend using a separate tool to perform tree shaking on the output.