Skip to content

Commit fd67d72

Browse files
committed
feat: add chunk matcher for mf
1 parent 666455c commit fd67d72

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

crates/mako/src/generate/chunk_pot/util.rs

+10
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ pub(crate) fn runtime_code(context: &Arc<Context>) -> Result<String> {
105105
let chunk_graph = context.chunk_graph.read().unwrap();
106106
let has_dynamic_chunks = chunk_graph.get_all_chunks().len() > 1;
107107
let has_hmr = context.args.watch;
108+
let chunk_matcher = context.config.module_federation.as_ref().and_then(|mf| {
109+
mf.remotes.as_ref().and_then(|remotes| {
110+
if remotes.is_empty() {
111+
None
112+
} else {
113+
Some(r#"/^mako\/container\/remote\//"#.to_string())
114+
}
115+
})
116+
});
108117
let app_runtime = AppRuntimeTemplate {
109118
has_dynamic_chunks,
110119
has_hmr,
@@ -127,6 +136,7 @@ pub(crate) fn runtime_code(context: &Arc<Context>) -> Result<String> {
127136
.as_ref()
128137
.map_or(false, |o| o.concatenate_modules.unwrap_or(false)),
129138
global_module_registry: context.config.output.global_module_registry,
139+
chunk_matcher,
130140
};
131141
let app_runtime = app_runtime.render_once()?;
132142
let app_runtime = app_runtime.replace(

crates/mako/src/generate/runtime.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ pub struct AppRuntimeTemplate {
1414
pub concatenate_enabled: bool,
1515
pub cross_origin_loading: Option<String>,
1616
pub global_module_registry: bool,
17+
pub chunk_matcher: Option<String>,
1718
}

crates/mako/templates/app_runtime.stpl

+5-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function createRuntime(makoModules, entryModuleId, global) {
7171
// required modules
7272
requireModule.m = makoModules;
7373

74-
// required modules
74+
// modules registry
7575
requireModule.c = modulesRegistry;
7676

7777
<% if concatenate_enabled { %>
@@ -136,7 +136,10 @@ function createRuntime(makoModules, entryModuleId, global) {
136136
if (data === 0) return;
137137

138138
// skip federation remote chunk
139-
if (chunkId.startsWith("mako/container/remote/")) return;
139+
140+
<% if chunk_matcher.is_some() { %>
141+
if (<%= chunk_matcher.unwrap() %>.test(chunkId)) return
142+
<% } %>
140143

141144
if (data) {
142145
// 0 1 2

0 commit comments

Comments
 (0)