Skip to content

Conversation

@LingyuCoder
Copy link
Contributor

Summary

port webpack/webpack#17308 from webpack

Related links

Checklist

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

Copilot AI review requested due to automatic review settings October 31, 2025 08:09
@netlify
Copy link

netlify bot commented Oct 31, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 5c6aaa7
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/69046ee9a9cd1d0008a01711

@github-actions github-actions bot added release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack. labels Oct 31, 2025
@LingyuCoder LingyuCoder requested a review from JSerFeng October 31, 2025 08:09
@LingyuCoder LingyuCoder changed the title fix: compatibility __non_webpack_require__ with es modules fix: compatibility __non_webpack_require__ with es modules Oct 31, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the createRequire usage in ESM output by creating a single reusable variable instead of calling __WEBPACK_EXTERNAL_createRequire(import.meta.url) repeatedly. The change introduces __WEBPACK_EXTERNAL_createRequire_require as a cached result of the createRequire() call, which is then reused throughout the module.

Key changes:

  • Introduces __WEBPACK_EXTERNAL_createRequire_require variable to cache the result of createRequire(import.meta.url)
  • Updates all usage sites to reference the cached variable instead of calling createRequire() repeatedly
  • Ensures concatenated modules properly propagate the need_create_require flag

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/rspack_plugin_javascript/src/plugin/api_plugin.rs Generates the cached createRequire variable with environment-aware const/var keyword
crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs Updates non-webpack require references to use the cached variable
crates/rspack_core/src/external_module.rs Updates external module generation to create and use the cached variable
crates/rspack_core/src/concatenated_module.rs Propagates need_create_require flag from nested modules
tests/rspack-test/configCases/module/issue-17971/test.filter.js Enables previously disabled test (fixed by this change)
tests/rspack-test/configCases/module/issue-19767/test.filter.js Removes test filter (test now passes)
tests/rspack-test/configCases/module/entries-runtime-false/test.filter.js Removes test filter (test now passes)
tests/rspack-test/configCases/module/dependOn-runtime-false/test.filter.js Removes test filter (test now passes)
tests/rspack-test/esmOutputCases/dynamic-import/magic-comment/snapshots/esm.snap.txt Updates snapshot to reflect new cached variable usage
tests/rspack-test/configCases/library/modern-module-force-concaten/snapshot/f.js.txt Updates snapshot to reflect new cached variable usage
tests/rspack-test/configCases/library/esm-external/index.js Updates test expectations to match new variable name
tests/rspack-test/configCases/externals/module-import/index.js Updates test expectations to match new variable name

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

📦 Binary Size-limit

Comparing 5c6aaa7 to fix: should increase the counter of sized in mangle exports plugin (#12044) by harpsealjs

❌ Size increased by 256bytes from 47.84MB to 47.84MB (⬆️0.00%)

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 31, 2025

CodSpeed Performance Report

Merging #12052 will not alter performance

Comparing fix/esm-non-webpack-require (5c6aaa7) with main (0ff711f)

Summary

✅ 17 untouched

@LingyuCoder LingyuCoder enabled auto-merge (squash) October 31, 2025 09:09
@LingyuCoder LingyuCoder merged commit bd93cf1 into main Oct 31, 2025
70 of 72 checks passed
@LingyuCoder LingyuCoder deleted the fix/esm-non-webpack-require branch October 31, 2025 09:09
@h-a-n-a h-a-n-a mentioned this pull request Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants