-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Turn elements/index into an index #7135
Conversation
@@ -1,6 +1,6 @@ | |||
import DatasetController from '../core/core.datasetController'; | |||
import defaults from '../core/core.defaults'; | |||
import Rectangle from '../elements/element.rectangle'; | |||
import {Rectangle} from '../elements/index'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested it, but from reading the docs it sounds like webpack will do a better job of tree shaking at least in some scenarios depending on the options the user has set if we leave the import statement as import Rectangle from '../elements/element.rectangle';
. It sounds like it has different modes where it either looks at just import
/export
or sometimes tries to figure out if code has side-effects although that's tougher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fail to find such information than webpack's guide. Most of the examples import non default exports there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing non-default export is fine. I'm more worried about transitively importing things that aren't used. I.e. the existence of elements/index
. Webpack does tree shaking at a file level by default and not a method level, so this stops the other elements from just falling out
I'm a little less worried about elements/index
if nothing refers to it though except the entry point and we make a new entry point for tree shaking which doesn't use it at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should make it possible to have export * from ./elements
in that new entry point.
Should we close this one if we're going with #7149? I'm wondering what our overall plan looks like with tree shaking. #7149 would make it harder to set |
I intentionally changed the index file to directly re-export everything instead of bundling them into an object and exporting that. I think most if not all bundlers can handle that. Also if you look #7149 more carefully, I did the same there. Only thing missing (for scales) is the index.esm.js in /src that re-exports everything we want to export form the .esm.js public package. |
I just tested this in a WebPack project and it didn't remove it |
Thanks for testing. I could not know what you tested and how and what it did not remove, so I tested myself. The test repo is here: https://github.com/kurkle/webpack-tree-shaking-tests Outcome: |
Ah, it seems like the difference is I just used WebPack directly whereas you built with Rollup first and then WebPack. I guess it depends how we set things up for tree shaking Let's say that we build things with Rollup first. How does that work together with the |
The "self registration" as done in #7149 registers the scale when imported. So it will not make all scales register, unless all are imported. Other options are internal registration of all scales (disables tree shaking) and some kind of post import registration. And of course the "no registration", where the scales would be defined with instance or constructor instead of the current name. |
The entry point compiled by rollup may have to import everything, but it depends how we set things up. I think there's a few different ways we can set things up and it's hard for me to figure out what we want to do here and in #7149 without the full picture of where we're going. Maybe we should have a ticket just to discuss the overall higher-level strategy or discuss on Slack? I think there's two main options, which I tried to outline in #7009 (comment). I think this PR is helpful for option 1 and self-registration is helpful for option 2. I don't know that it makes sense to do both. We originally decided in #6979 that option 2 wasn't feasible because of the CSS plugin, but now that it's been removed I think it should be feasible and would be my preference. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fine assuming we create a new entry point for tree shaking, get rid of auto-registration, and set sideEffects: false
I think we only need the src/index.js to be a monolith.