-
-
Notifications
You must be signed in to change notification settings - Fork 759
feat(plugin_mf): Module Hoisting, Entry initialization via __webpack_require__.x, Custom Hooks #10524
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
Merged
+1,444
−127
Merged
feat(plugin_mf): Module Hoisting, Entry initialization via __webpack_require__.x, Custom Hooks #10524
Changes from 37 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
5a73444
feat(module-federation): add HoistContainerReferencesPlugin
ScriptedAlchemy 10881bb
fix(federation): update ModuleFederationPlugin to use finishMake hook
ScriptedAlchemy 2d019a7
feat(mf): implement Module Federation runtime system in Rust - Add Em…
ScriptedAlchemy d83d6a5
refactor(mf): clean up debug macros and logging from development - Re…
ScriptedAlchemy 70ef9df
feat(test): convert Module Federation webpack configs to rspack confi…
ScriptedAlchemy 0b308a1
feat: add intelligent build optimization and clean up basic example s…
ScriptedAlchemy effb92b
choreL lock
ScriptedAlchemy 4cc9a2d
refactor(container): simplify import statement for ExposeOptions in c…
ScriptedAlchemy 6029eb4
feat: implement EmbedFederationRuntimePlugin for module federation ru…
ScriptedAlchemy d0f2d83
refactor(plugin-mf): remove unused EmbedFederationRuntimePluginOption…
ScriptedAlchemy e1c3814
fix(plugin-mf): resolve clippy warnings and add missing runtime_chunk…
ScriptedAlchemy f21a105
refactor(plugin-mf): remove debugging println statements from contain…
ScriptedAlchemy d80fb1c
docs(plugin-mf): add comprehensive documentation to container plugins…
ScriptedAlchemy 95e5425
docs(plugin-mf): enhance EmbedFederationRuntimePlugin documentation w…
ScriptedAlchemy 271795a
docs(plugin-mf): correct STARTUP runtime requirement documentation - …
ScriptedAlchemy a81b193
docs(plugin-mf): simplify and streamline all container plugin documen…
ScriptedAlchemy 0bd4ad5
docs(plugin-mf): further simplify federation startup call comment - C…
ScriptedAlchemy 7bbdaf5
refactor(plugin-mf): clean up comments in ModuleFederationRuntimePlug…
ScriptedAlchemy 6652291
docs(plugin-mf): remove verbose documentation from ContainerPlugin - …
ScriptedAlchemy 4b4b57c
chore: fix example
ScriptedAlchemy cc40e47
refactor(plugin-mf): clean up remaining comments in container plugins…
ScriptedAlchemy 4328cfe
refactor: rename federation_runtime_module to federation_data_runtime…
ScriptedAlchemy ef69998
refactor: fix import style in container_plugin.rs for consistency
ScriptedAlchemy 3dc7649
refactor: remove unnecessary variable declarations in hook calls
ScriptedAlchemy b8b8850
Merge branch 'main' into hoist-container-references
ScriptedAlchemy 637872c
fix: resolve compilation errors in plugin_mf
ScriptedAlchemy 410040a
Merge branch 'main' into hoist-container-references
ScriptedAlchemy 91d3abf
chore: revert mistakes
ScriptedAlchemy 74508ad
chore: revert mistakes
ScriptedAlchemy 0ba4e5a
refactor: remove unused runtime_chunk option from ModuleFederationRun…
ScriptedAlchemy 28db4f8
refactor: consolidate federation dependency processing in HoistContai…
ScriptedAlchemy fae970d
chore: remove unused dependencies from rspack_plugin_mf (rkyv, once_c…
ScriptedAlchemy 69ed29e
chore: update Cargo.lock after removing unused dependencies
ScriptedAlchemy 9617f90
test: fix Module Federation runtime test to handle both CommonJS and …
ScriptedAlchemy e1ff251
Merge branch 'main' into hoist-container-references
ScriptedAlchemy 4bf769a
test: fix Module Federation test for Windows path separators
ScriptedAlchemy f50ac94
Merge branch 'main' into hoist-container-references
ScriptedAlchemy 6438807
Resolve merge conflicts in Module Federation plugin
ScriptedAlchemy 0372784
feat: sync Module Federation enhancements from external PR #3903
ScriptedAlchemy 05c2bda
Merge branch 'main' into hoist-container-references
ScriptedAlchemy c0e3751
fix: resolve clippy warnings in federation_data_runtime_module
ScriptedAlchemy 7038f14
fix: resolve all clippy warnings in Module Federation plugin
ScriptedAlchemy 9db7558
Merge branch 'main' into hoist-container-references
ScriptedAlchemy 402da01
chore: remove edits
ScriptedAlchemy 07f4858
Optimize binary size in Module Federation plugin
ScriptedAlchemy 566ec2d
Further optimize binary size in Module Federation plugin
ScriptedAlchemy c5c3e07
Revert variable name minification in generated JavaScript
ScriptedAlchemy 30b4621
Revert runtime module JavaScript minification
ScriptedAlchemy 9285899
Resolve merge conflict: use main branch version of binding.d.ts
ScriptedAlchemy acfeaed
Merge branch 'main' into hoist-container-references
ScriptedAlchemy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
crates/rspack_plugin_mf/src/container/embed_federation_runtime_module.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
//! # EmbedFederationRuntimeModule | ||
//! | ||
//! Runtime module that wraps the startup function to ensure federation runtime dependencies | ||
//! execute before other modules. Generates an "oldStartup wrapper" pattern that intercepts | ||
//! and modifies the startup execution order. | ||
|
||
use rspack_cacheable::cacheable; | ||
use rspack_collections::Identifier; | ||
use rspack_core::{ | ||
impl_runtime_module, module_raw, ChunkUkey, Compilation, DependencyId, RuntimeGlobals, | ||
RuntimeModule, RuntimeModuleStage, | ||
}; | ||
use rspack_error::Result; | ||
|
||
#[cacheable] | ||
#[derive(Debug, Default, Clone, Hash, PartialEq, Eq)] | ||
pub struct EmbedFederationRuntimeModuleOptions { | ||
pub collected_dependency_ids: Vec<DependencyId>, | ||
} | ||
|
||
#[impl_runtime_module] | ||
#[derive(Debug)] | ||
pub struct EmbedFederationRuntimeModule { | ||
id: Identifier, | ||
chunk: Option<ChunkUkey>, | ||
options: EmbedFederationRuntimeModuleOptions, | ||
} | ||
|
||
impl EmbedFederationRuntimeModule { | ||
pub fn new(options: EmbedFederationRuntimeModuleOptions) -> Self { | ||
Self::with_default( | ||
Identifier::from("webpack/runtime/embed_federation_runtime"), | ||
None, | ||
options, | ||
) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl RuntimeModule for EmbedFederationRuntimeModule { | ||
fn name(&self) -> Identifier { | ||
self.id | ||
} | ||
|
||
async fn generate(&self, compilation: &Compilation) -> Result<String> { | ||
let chunk_ukey = self | ||
.chunk | ||
.expect("Chunk should be attached to RuntimeModule"); | ||
|
||
let collected_deps = &self.options.collected_dependency_ids; | ||
|
||
if collected_deps.is_empty() { | ||
return Ok("// No federation runtime dependencies to embed.".to_string()); | ||
} | ||
|
||
let module_graph = compilation.get_module_graph(); | ||
let mut federation_runtime_modules = Vec::new(); | ||
|
||
// Find federation runtime dependencies in this chunk | ||
for dep_id in collected_deps.iter() { | ||
if let Some(module_dyn) = module_graph.get_module_by_dependency_id(dep_id) { | ||
let is_in_chunk = compilation | ||
.chunk_graph | ||
.is_module_in_chunk(&module_dyn.identifier(), chunk_ukey); | ||
if is_in_chunk { | ||
federation_runtime_modules.push(*dep_id); | ||
} | ||
} | ||
} | ||
|
||
if federation_runtime_modules.is_empty() { | ||
return Ok("// Federation runtime entry modules not found in this chunk.".to_string()); | ||
} | ||
|
||
// Generate module execution code for each federation runtime dependency | ||
let mut runtime_requirements = RuntimeGlobals::default(); | ||
let mut module_executions = Vec::new(); | ||
|
||
for dep_id in federation_runtime_modules { | ||
let module_str = module_raw(compilation, &mut runtime_requirements, &dep_id, "", false); | ||
module_executions.push(format!("\t\t{}", module_str)); | ||
} | ||
|
||
// Generate oldStartup wrapper pattern | ||
let result = format!( | ||
r#"var oldStartup = {startup}; | ||
var hasRun = false; | ||
{startup} = function() {{ | ||
if (!hasRun) {{ | ||
hasRun = true; | ||
{module_executions} | ||
}} | ||
return oldStartup(); | ||
}};"#, | ||
startup = RuntimeGlobals::STARTUP.name(), | ||
module_executions = module_executions.join("\n") | ||
); | ||
|
||
Ok(result) | ||
} | ||
|
||
fn attach(&mut self, chunk: ChunkUkey) { | ||
self.chunk = Some(chunk); | ||
} | ||
|
||
fn stage(&self) -> RuntimeModuleStage { | ||
RuntimeModuleStage::from(11) // Run after RemoteRuntimeModule (stage 10) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
patch webpack_require.x which is entry startup function.
first initialize federation, then call previous startup if exists - if it exists, it will be webpack require of entrypoint module.
If startup doesnt exist in entrypoint bootstrap, like in single runtime chunk, another plugin will manually add require.x() to the entrypoint chunks at the begenning of startup