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

feat(modern-module): make dynamic import runtime-less #7759

Merged
merged 1 commit into from
Sep 5, 2024

Conversation

fi3ework
Copy link
Member

@fi3ework fi3ework commented Sep 2, 2024

Summary

modern-module reduces the runtime code for external modules with dynamic import.

// source
const react = import('react')

// before
// ---snip---
"357": (function (module) {
module.exports = __WEBPACK_EXTERNAL_MODULE_react_alias__;
}),
// ---snip---
const react = await Promise.resolve(/* import() */ ).then(__webpack_require__.bind(__webpack_require__, 357))

// after
const react = import('react')

What did this PR mainly do:

  1. In finish_modules hook of modern-module, find all ImportDependency dependencies that point to external modules.
  2. In the module graph, find the block to which the dependency belongs and remove this dep; find the connection associated with this dependency and revoke it.
  3. Add a new dependency to complete the ID replacement for the external module.

Concern:

The connection is revoked, does it need to add a new connection between the original module and external module with the new dependency, is there a proper method to do that?

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Sep 2, 2024
Copy link

netlify bot commented Sep 2, 2024

Deploy Preview for rspack canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit c73c237
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/66d96e08f9b91e0008a3b226

@fi3ework fi3ework force-pushed the compact-dynamic-import branch 2 times, most recently from cdb0cb7 to 819b148 Compare September 2, 2024 12:44
@fi3ework fi3ework marked this pull request as ready for review September 5, 2024 09:46
@fi3ework fi3ework merged commit d9a6d59 into web-infra-dev:main Sep 5, 2024
39 checks passed
@fi3ework fi3ework deleted the compact-dynamic-import branch September 5, 2024 14:21
shulaoda pushed a commit to shulaoda/rspack that referenced this pull request Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: feature release: feature related release(mr only)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants