-
Notifications
You must be signed in to change notification settings - Fork 58
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
Make this package tree-shakeable #39
Comments
I have the impression this might break compatibility with Webpack: webpack/webpack#5756 I'd rather not spend energy getting experimental with the build for this library. Is there no way your downstream UI library can structure itself to optimize for tree-shaking? For example, if this module were only imported by the UI components that use it — why wouldn't tree-shaking work then, for consumers of the UI library? |
It won't if you are going to provide same exports shape for both ESM & CJS files - the compatibility only breaks when people try to use so called auto exports for CJS, so basically transforming
Unfortunately bundlers, minifiers & such are quite conservative regarding this stuff. Most of the bundlers simply bail out on CJS files because of its dynamic nature (even though most of the real world files have static exports). In order to perform safe tree shaking a tool has to analyze the program and if it's unsure if a statement has no side effects then it's marked as unsafe to be removed. I've illustrated this problem some time ago with a simple repro case. Consider a simple structure:
|
After #59, I believe the only thing left is adding |
@stefcameron Even though my entry point only uses stuff unrelated to tabbable the non-treeshakable code in tabbable is still left in the bundle: https://github.com/Andarist/tabbable-tree-shaking-issue-demo/blob/5a2339a20353dce91786c3467048e22cab1e9a6c/dist/main.js#L58-L75 |
I see, thanks for pointing that out. Doesn't hurt, but seems ineffective. Thanks for #70 |
I'm building a UI library which exports a bunch of stuff, only some of my components rely on this package so it would be desirable that if a consumer of my package doesn't use component relying on
tabbable
it would be tree shaken out of the final bundle. However it's not the case right now.Let's focus on 2 common tree-shaking deopts:
module.exports = tabbable; tabbable.isTabbable = isTabbable;
Action items:
export default tabbable; export { isTabbable, isFocusable };
Intent to implement - yes (was already implemented in #38 )
The text was updated successfully, but these errors were encountered: