-
-
Notifications
You must be signed in to change notification settings - Fork 746
refactor: render runtime root variables by runtime template #12308
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
Conversation
✅ Deploy Preview for rspack canceled.
|
There was a problem hiding this 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 refactors the codebase to use a template-based approach for rendering runtime root variables (like __webpack_require__, __webpack_modules__, __webpack_module_cache__, __webpack_exports__) instead of hardcoded strings. This is achieved by introducing a new RuntimeVariable enum and corresponding render_runtime_variable() method on RuntimeTemplate.
Key changes:
- Added
RuntimeVariableenum with variants for common runtime variables (Require, Modules, ModuleCache, Module, Exports, EsmChunkIds, EsmChunkId, EsmRuntime) - Introduced
render_runtime_variable(),render_exports_argument(), andrender_module_argument()methods onRuntimeTemplate - Removed
Displaytrait implementations fromModuleArgumentandExportsArgumentenums in favor of the new rendering methods - Updated all callsites across plugins to use the new template-based rendering approach
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
crates/rspack_core/src/runtime_globals.rs |
Added RuntimeVariable enum and runtime_variable_to_string() function; updated runtime_globals_to_string() to use the new function |
crates/rspack_core/src/runtime_template.rs |
Added render_runtime_variable(), render_exports_argument(), and render_module_argument() methods |
crates/rspack_core/src/module.rs |
Removed Display trait implementations for ModuleArgument and ExportsArgument |
crates/rspack_core/src/lib.rs |
Exported RuntimeVariable alongside RuntimeGlobals |
crates/rspack_plugin_runtime/src/runtime_module/export_require.rs |
Removed hardcoded constant and now dynamically generates temporary variable name |
crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs |
Updated to use render_runtime_variable() for ESM chunk IDs, modules, and runtime |
crates/rspack_plugin_runtime/src/runtime_module/make_deferred_namespace_object_runtime.rs |
Updated to use render_runtime_variable() for module cache |
crates/rspack_plugin_runtime/src/runtime_module/async_module.rs |
Updated to use render_runtime_variable() for module cache |
crates/rspack_plugin_runtime/src/module_chunk_format.rs |
Updated to use render_runtime_variable() for ESM chunk variables, modules, runtime, and exports |
crates/rspack_plugin_runtime/src/helpers.rs |
Updated to use render_runtime_variable() for exports in entry startup generation |
crates/rspack_plugin_runtime/src/array_push_callback_chunk_format.rs |
Updated to use render_runtime_variable() for exports |
crates/rspack_plugin_library/src/module_library_plugin.rs |
Updated to use render_runtime_variable() for exports |
crates/rspack_plugin_library/src/modern_module_library_plugin.rs |
Updated to use render_runtime_variable() for exports |
crates/rspack_plugin_library/src/assign_library_plugin.rs |
Updated to use render_runtime_variable() for exports; has duplicate variable declaration |
crates/rspack_plugin_javascript/src/runtime.rs |
Updated to use render_module_argument() and render_exports_argument() |
crates/rspack_plugin_javascript/src/plugin/mod.rs |
Updated to use render_runtime_variable(), render_module_argument(), and render_exports_argument() throughout |
crates/rspack_plugin_javascript/src/dependency/module_argument_dependency.rs |
Updated to use render_module_argument() |
crates/rspack_plugin_javascript/src/dependency/esm/esm_export_imported_specifier_dependency.rs |
Updated to use render_exports_argument() |
crates/rspack_plugin_javascript/src/dependency/esm/esm_export_expression_dependency.rs |
Updated to use render_exports_argument() |
crates/rspack_plugin_javascript/src/dependency/esm/esm_compatibility_dependency.rs |
Updated to use render_exports_argument() and render_module_argument() |
crates/rspack_plugin_javascript/src/dependency/commonjs/module_decorator_dependency.rs |
Updated to use render_module_argument() |
crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_self_reference_dependency.rs |
Updated to use render_exports_argument() and render_module_argument() |
crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_exports_dependency.rs |
Updated to use render_exports_argument() and render_module_argument() |
crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_export_require_dependency.rs |
Updated to use render_exports_argument() and render_module_argument() |
crates/rspack_plugin_esm_library/src/render.rs |
Updated to use render_runtime_variable() for modules and module cache |
crates/rspack_core/src/init_fragment.rs |
Updated to use render_exports_argument() |
crates/rspack_core/src/concatenated_module.rs |
Updated to use render_exports_argument() |
tests/rspack-test/esmOutputCases/split-chunks/export-temp-runtime/__snapshots__/esm.snap.txt |
Updated snapshot showing corrected temporary variable naming |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📦 Binary Size-limit
❌ Size increased by 9.63KB from 47.67MB to 47.68MB (⬆️0.02%) |
CodSpeed Performance ReportMerging #12308 will not alter performanceComparing Summary
|
Summary
Render runtime root variables like
__webpack_require__/__webpack_modules__/__webpack_module_cache__by runtime template.Related links
Checklist