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

ESM - Angular 10 Tree Shaking Support? #155

Open
anh-rivergon opened this issue Nov 16, 2020 · 3 comments
Open

ESM - Angular 10 Tree Shaking Support? #155

anh-rivergon opened this issue Nov 16, 2020 · 3 comments

Comments

@anh-rivergon
Copy link

WARNING in MyLogging.js depends on 'loglevel'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

How would I get rid of the warning? This happens during tree shaking and I'd like ascertain that optimization does take place?

Thank-you

@anh-rivergon anh-rivergon changed the title ESM - Angular 10 Support? ESM - Angular 10 Tree Shaking Support? Nov 16, 2020
@pimterry
Copy link
Owner

I don't know anything about Angular's build process I'm afraid. However, I imagine the optimization is an analysis of how loglevel's exports are used, and whether that means that some of loglevel's own dependencies or code can be omitted from your bundle. Since loglevel is tiny and doesn't have any dependencies at all, you can safely skip that anyway, it shouldn't make any significant difference. I don't imagine that this disables all optimizations in your build, just the optimization of your loglevel usage specifically.

You can test this easily enough - try commenting our your import(s) of loglevel, and compare the bundle size to your normal build. If it makes no difference, the bundle size should differ only by the approximate size of loglevel itself, about 3KB. If it differs by a lot more that that, there's a larger problem where this is affecting your build optimizations. Assuming it indeed doesn't cause any problems, you can disable the warning using allowedCommonJsDependencies as in your link there.

This could also be fixed by migrating loglevel to ESM - if you're really interested, I'd be open to a PR that added that as an output from the build process, but it's a bit complicated to do whilst preserving the existing setup.

@anh-rivergon
Copy link
Author

"This could also be fixed by migrating loglevel to ESM - if you're really interested, I'd be open to a PR that added that as an output from the build process, but it's a bit complicated to do whilst preserving the existing setup."

Absolutely :) I was looking for an ESM version of loglevel. That should solve the issue.

@pimterry
Copy link
Owner

Ok, great! Feel free to open a PR for that, let me know if you have any questions en route. I do want to continue to support the existing UMD output, but I would be very happy to support more formats too if there's interest.

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

No branches or pull requests

2 participants