-
-
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
Dynamic Imports that are marked external are hoisted #17986
Comments
I want to say it is not a bug, just change I think we should add a new value for |
Also you can specify the type for an each item using https://webpack.js.org/configuration/externals/#string |
Thank you @alexander-akait , that actually solves the hoisting, but it brings that hoisting still back to the main bundle into a function. For example, I don't think we need another My recommendation would be to keep |
@mohamedmansour No, it is not a bug, I can't find a discussion about it, but there was already a question about it here, there are scenarios when developers want to hoist (preload big modules in the first run), some want to load dynamically (lazy evaluation), especial in diffucult applications (you can improve perf in some cases, for example some modules can take a lot of time on import but you used them in rare cases and you can't change vendor library code), that is why I said, we need the another value to allow to keep dynamic import as dynamic and static as static. The same logic works for other values of the |
It is actually a more serious bug when we move to We need true browser platform ESM outputs. In the example below,
For example, index.ts
chrome.js
app.js
To your question, when developers want to hoist big modules, can't they just do the following which solves that scenario:
Since Doing some re-arrangement to assume all "dynamic" imports get hoisted to the top, breaks a core use case of dynamic imports. |
As I said above we just need a new value - |
This issue had no activity for at least three months. It's subject to automatic issue closing if there is no activity in the next 15 days. |
Bump (activity) |
Given this code:
Where we mark
b.js
as external, the bundler prints this:It should rather be:
Webpack hoists all external dynamic imports to the very top, not making it dynamic import. Which defeats its purpose.
It would be great if Webpack does not wrap native ESM imports with promises as well.
Other relevant information:
"webpack": "5.89.0",
"webpack-cli": "5.1.4",
"webpack-dev-server": "4.15.1",
The text was updated successfully, but these errors were encountered: