Conversation
There was a problem hiding this comment.
Pull request overview
Fixes ESM library output when optimization.runtimeChunk: false so entry chunks that also act as the runtime chunk don’t emit/export unnecessary __webpack_require__ scaffolding.
Changes:
- Adjust ESM library rendering to only export
__webpack_require__from pure runtime chunks (no entry modules). - Stop generating an empty
var __webpack_require__ = {};when onlyREQUIRE_SCOPEis present without realREQUIREusage. - Add an ESM output test case covering
runtimeChunk: falseand snapshotting the cleaned output.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
crates/rspack_plugin_esm_library/src/render.rs |
Tightens __webpack_require__ export conditions; removes empty require-scope emission. |
crates/rspack_plugin_esm_library/src/plugin.rs |
Attempts to gate adding RuntimeGlobals::REQUIRE behind an ESM-library-specific “needs require” signal. |
tests/rspack-test/esmOutputCases/basic/runtime-chunk-false/rspack.config.js |
New test config setting optimization.runtimeChunk: false. |
tests/rspack-test/esmOutputCases/basic/runtime-chunk-false/index.js |
New test asserting runtime behavior. |
tests/rspack-test/esmOutputCases/basic/runtime-chunk-false/lib.js |
Simple exported value used by the test. |
tests/rspack-test/esmOutputCases/basic/runtime-chunk-false/__snapshots__/esm.snap.txt |
Snapshot ensuring no __webpack_require__ artifacts in output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… when runtimeChunk is false
When runtimeChunk is false, the entry chunk serves as both the entry and
runtime chunk. Previously this caused two issues:
1. __webpack_require__ was exported from the entry even though no other
chunk imports it (only pure runtime chunks should export it).
2. An empty `var __webpack_require__ = {};` scope was generated when
REQUIRE_SCOPE was triggered by STARTUP_NO_DEFAULT without actual
REQUIRE usage.
3. REQUIRE was added to chunk requirements whenever any requirement
existed, even if unrelated to __webpack_require__ usage.
Fix by: checking for entry modules before exporting __webpack_require__,
removing the useless require scope generation, and only adding REQUIRE
when ESM library features (external modules, interop) actually need it.
5832dc6 to
8ce82f9
Compare
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 5 projects with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 react-10kPath:
📁 react-1kPath:
📁 react-5kPath:
📁 romePath:
📁 ui-componentsPath:
Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
❌ Size increased by 896bytes from 49.00MB to 49.00MB (⬆️0.00%) |
Merging this PR will not alter performance
Comparing Footnotes
|
…ntime without export
…_SCOPE guard - Rename `is_entry_chunk` to `is_pure_runtime_chunk` and flip the condition so the export guard reads positively: only pure runtime chunks export `__webpack_require__`. - Replace the blanket `needs_require` flag with a REQUIRE_SCOPE_GLOBALS intersection check (same logic the runtime plugin uses in handle_scope_globals). This ensures REQUIRE_SCOPE is only added when the chunk actually contains globals that live on the __webpack_require__ object, rather than for any non-empty requirement set.
Summary
When
runtimeChunkis set tofalse, the entry chunk serves as both the entry and the runtime chunk. Three issues existed in this scenario:__webpack_require__was exported from the entry chunk even though no other chunk imports it. Only pure runtime chunks (created byoptimize_runtime_chunks) should export it.var __webpack_require__ = {};scope was generated whenREQUIRE_SCOPEwas triggered bySTARTUP_NO_DEFAULTwithout any actualREQUIREusage.REQUIREwas unconditionally added to chunk runtime requirements whenever any requirement was present, even for unrelated module codegen requirements that have nothing to do with__webpack_require__.Changes
render.rs:__webpack_require__. Entry-with-runtime chunks (i.e.runtimeChunk: false, not split) must not export it, since nothing imports from them.else if require_scope_usedbranch that generatedvar __webpack_require__ = {};. In the ESM library context,REQUIRE_SCOPEwithoutREQUIREis only triggered bySTARTUP_NO_DEFAULTand produces dead code.plugin.rs:__webpack_require__, and only insertREQUIREwhen that is the case.Test plan
esmOutputCases/basic/runtime-chunk-falsetest case that verifies a simple ESM entry withruntimeChunk: falseproduces clean output with no__webpack_require__artifacts.