Skip to content

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

Merged
fi3ework merged 1 commit intoweb-infra-dev:mainfrom
fi3ework:compact-dynamic-import
Sep 5, 2024
Merged

feat(modern-module): make dynamic import runtime-less#7759
fi3ework merged 1 commit intoweb-infra-dev:mainfrom
fi3ework:compact-dynamic-import

Conversation

@fi3ework
Copy link
Copy Markdown
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
@netlify
Copy link
Copy Markdown

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 force-pushed the compact-dynamic-import branch from 819b148 to c73c237 Compare September 5, 2024 08:38
@fi3ework fi3ework marked this pull request as ready for review September 5, 2024 09:46
@fi3ework fi3ework requested a review from ahabhgk September 5, 2024 09:49
@fi3ework fi3ework merged commit d9a6d59 into web-infra-dev:main Sep 5, 2024
@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