Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: can we get list of tree-shaken modules (which were marked as external?) #1939

Closed
chrisui opened this issue Jan 14, 2022 · 4 comments
Labels

Comments

@chrisui
Copy link

chrisui commented Jan 14, 2022

This would be useful for building up minimal package.json dependencies of lambda functions. We track modules marked as external to create and install the minimal production dependencies for a given entry point however we currently (without a second parse) know if any of these external modules were dead-code anyway (which tree-shaking encapsulates the logic of).

Is it possible to expose this if it's not available already?

@chrisui chrisui changed the title Question: can we get list of tree-shaken modules which were marked as external? Question: can we get list of tree-shaken modules (which were marked as external?) Jan 14, 2022
@hyrious
Copy link

hyrious commented Jan 15, 2022

You can use plugins to track every import expression and mark some of them as external and collect them. In fact, I had the same requirement months ago to help me find out unused dependencies in package.json, and I quickly written one:
https://github.com/hyrious/esbuild-dev/blob/b551d77e2ce6d9a908a9ca4056aa5d980031c573/src/utils.ts#L34

@chrisui
Copy link
Author

chrisui commented Jan 15, 2022

You can use plugins to track every import expression and mark some of them as external and collect them. In fact, I had the same requirement months ago to help me find out unused dependencies in package.json, and I quickly written one: https://github.com/hyrious/esbuild-dev/blob/b551d77e2ce6d9a908a9ca4056aa5d980031c573/src/utils.ts#L34

Cheers. We do actually have a plugin that collects these however resolve appears to happen before tree-shaking meaning that you will collect modules that may never actually be used (as indicated by the fact the tree-shaking algorithm removes them from the bundle later).

@tinovyatkin
Copy link

tinovyatkin commented Jan 17, 2022

We are reparsing bundle with Typescript (as we had that available in CDK, but you may use any other, including esbuild itself) like that https://gist.github.com/tinovyatkin/727ddbf7e7e10831a1eca9e4ff2fc32e. As as reporting in #1933 the imports field from metadata may be very useful for that, but, unfortunately, it's not getting populated.

@evanw evanw added the metafile label Dec 4, 2022
@evanw evanw closed this as completed in f2f78ef Dec 14, 2022
@chrisui
Copy link
Author

chrisui commented Feb 28, 2023

Thank you @evanw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants