-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Lazy loading only required exports from dynamic import() #10964
Lazy loading only required exports from dynamic import() #10964
Conversation
For maintainers only:
|
I think supporting |
@pushkar100 Thanks for your update. I labeled the Pull Request so reviewers will review it again. @sokra Please review the new changes. |
@pushkar100 What about if I want to export something as default - |
@evilebottnawi I did think about it. The import(/* webpackExports: "default" */ "./module")
.then(module => {/* only module.default is available */}) |
The code should keep working even if the comment is ignored (e.g. in native esm). So even if you only request a single export please return a namespace object for compat with native esm. |
One can use destructing for shorter syntax: |
@sokra @evilebottnawi I have prevented mangling of exports when Now we can use |
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.
A little bit refactoring to getReferencedExports
is needed to allow to pass the mangling info.
@sokra I have refactored the code: using an object for referenced exports with |
8bb314a
to
31e3369
Compare
@sokra I've incorporated the type and refactoring changes. An additional change in |
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
Thanks |
PR for the feature request #10959 (resolves #10959)
Adding magic comments to lazy load only named exports from a dynamically imported module.
Introducing
webpackExports: "<name>"
orwebpackExports: ["<name1>", "<name2>"]
At present, the entire module is exported. With this feature, we can reduce the code we import (i.e chunk files of smaller size are created)
What kind of change does this PR introduce?
feature
Did you add tests for your changes?
Yes (will add more when required)
Does this PR introduce a breaking change?
No
What needs to be documented once your changes are merged?