Skip to content

Commit 2c72081

Browse files
committed
is_module_merging_enabled on context, not in dev
1 parent 3afd4ec commit 2c72081

File tree

9 files changed

+187
-135
lines changed

9 files changed

+187
-135
lines changed

crates/next-core/src/next_client/context.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -470,23 +470,25 @@ pub async fn get_client_chunking_context(
470470
if next_mode.is_development() {
471471
builder = builder.hot_module_replacement().use_file_source_map_uris();
472472
} else {
473-
builder = builder.chunking_config(
474-
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
475-
ChunkingConfig {
476-
min_chunk_size: 50_000,
477-
max_chunk_count_per_group: 40,
478-
max_merge_chunk_size: 200_000,
479-
..Default::default()
480-
},
481-
);
482-
builder = builder.chunking_config(
483-
Vc::<CssChunkType>::default().to_resolved().await?,
484-
ChunkingConfig {
485-
max_merge_chunk_size: 100_000,
486-
..Default::default()
487-
},
488-
);
489-
builder = builder.use_content_hashing(ContentHashing::Direct { length: 16 })
473+
builder = builder
474+
.chunking_config(
475+
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
476+
ChunkingConfig {
477+
min_chunk_size: 50_000,
478+
max_chunk_count_per_group: 40,
479+
max_merge_chunk_size: 200_000,
480+
..Default::default()
481+
},
482+
)
483+
.chunking_config(
484+
Vc::<CssChunkType>::default().to_resolved().await?,
485+
ChunkingConfig {
486+
max_merge_chunk_size: 100_000,
487+
..Default::default()
488+
},
489+
)
490+
.use_content_hashing(ContentHashing::Direct { length: 16 })
491+
.module_merging(true);
490492
}
491493

492494
Ok(Vc::upcast(builder.build()))

crates/next-core/src/next_edge/context.rs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -255,20 +255,22 @@ pub async fn get_edge_chunking_context_with_client_assets(
255255
.module_id_strategy(module_id_strategy);
256256

257257
if !next_mode.is_development() {
258-
builder = builder.chunking_config(
259-
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
260-
ChunkingConfig {
261-
min_chunk_size: 20_000,
262-
..Default::default()
263-
},
264-
);
265-
builder = builder.chunking_config(
266-
Vc::<CssChunkType>::default().to_resolved().await?,
267-
ChunkingConfig {
268-
max_merge_chunk_size: 100_000,
269-
..Default::default()
270-
},
271-
);
258+
builder = builder
259+
.chunking_config(
260+
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
261+
ChunkingConfig {
262+
min_chunk_size: 20_000,
263+
..Default::default()
264+
},
265+
)
266+
.chunking_config(
267+
Vc::<CssChunkType>::default().to_resolved().await?,
268+
ChunkingConfig {
269+
max_merge_chunk_size: 100_000,
270+
..Default::default()
271+
},
272+
)
273+
.module_merging(true);
272274
}
273275

274276
Ok(Vc::upcast(builder.build()))
@@ -318,20 +320,22 @@ pub async fn get_edge_chunking_context(
318320
.module_id_strategy(module_id_strategy);
319321

320322
if !next_mode.is_development() {
321-
builder = builder.chunking_config(
322-
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
323-
ChunkingConfig {
324-
min_chunk_size: 20_000,
325-
..Default::default()
326-
},
327-
);
328-
builder = builder.chunking_config(
329-
Vc::<CssChunkType>::default().to_resolved().await?,
330-
ChunkingConfig {
331-
max_merge_chunk_size: 100_000,
332-
..Default::default()
333-
},
334-
);
323+
builder = builder
324+
.chunking_config(
325+
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
326+
ChunkingConfig {
327+
min_chunk_size: 20_000,
328+
..Default::default()
329+
},
330+
)
331+
.chunking_config(
332+
Vc::<CssChunkType>::default().to_resolved().await?,
333+
ChunkingConfig {
334+
max_merge_chunk_size: 100_000,
335+
..Default::default()
336+
},
337+
)
338+
.module_merging(true);
335339
}
336340

337341
Ok(Vc::upcast(builder.build()))

crates/next-core/src/next_server/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,8 @@ pub async fn get_server_chunking_context_with_client_assets(
10271027
SourceMapsType::None
10281028
})
10291029
.module_id_strategy(module_id_strategy)
1030-
.file_tracing(next_mode.is_production());
1030+
.file_tracing(next_mode.is_production())
1031+
.module_merging(next_mode.is_production());
10311032

10321033
if next_mode.is_development() {
10331034
builder = builder.use_file_source_map_uris();
@@ -1092,7 +1093,8 @@ pub async fn get_server_chunking_context(
10921093
SourceMapsType::None
10931094
})
10941095
.module_id_strategy(module_id_strategy)
1095-
.file_tracing(next_mode.is_production());
1096+
.file_tracing(next_mode.is_production())
1097+
.module_merging(next_mode.is_production());
10961098

10971099
if next_mode.is_development() {
10981100
builder = builder.use_file_source_map_uris()

turbopack/crates/turbopack-browser/src/chunking_context.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ impl BrowserChunkingContextBuilder {
9797
self
9898
}
9999

100+
pub fn module_merging(mut self, enable_module_merging: bool) -> Self {
101+
self.chunking_context.enable_module_merging = enable_module_merging;
102+
self
103+
}
104+
100105
pub fn asset_base_path(mut self, asset_base_path: ResolvedVc<Option<RcStr>>) -> Self {
101106
self.chunking_context.asset_base_path = asset_base_path;
102107
self
@@ -202,6 +207,8 @@ pub struct BrowserChunkingContext {
202207
enable_hot_module_replacement: bool,
203208
/// Enable tracing for this chunking
204209
enable_tracing: bool,
210+
/// Enable module merging
211+
enable_module_merging: bool,
205212
/// The environment chunks will be evaluated in.
206213
environment: ResolvedVc<Environment>,
207214
/// The kind of runtime to include in the output.
@@ -248,6 +255,7 @@ impl BrowserChunkingContext {
248255
asset_base_path: ResolvedVc::cell(None),
249256
enable_hot_module_replacement: false,
250257
enable_tracing: false,
258+
enable_module_merging: false,
251259
environment,
252260
runtime_type,
253261
minify_type: MinifyType::NoMinify,
@@ -510,6 +518,11 @@ impl ChunkingContext for BrowserChunkingContext {
510518
Vc::cell(self.enable_tracing)
511519
}
512520

521+
#[turbo_tasks::function]
522+
fn is_module_merging_enabled(&self) -> Vc<bool> {
523+
Vc::cell(self.enable_module_merging)
524+
}
525+
513526
#[turbo_tasks::function]
514527
pub fn minify_type(&self) -> Vc<MinifyType> {
515528
self.minify_type.cell()

turbopack/crates/turbopack-cli/src/build/mod.rs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,25 @@ async fn build_internal(
343343
match *node_env.await? {
344344
NodeEnv::Development => {}
345345
NodeEnv::Production => {
346-
builder = builder.chunking_config(
347-
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
348-
ChunkingConfig {
349-
min_chunk_size: 50_000,
350-
max_chunk_count_per_group: 40,
351-
max_merge_chunk_size: 200_000,
352-
..Default::default()
353-
},
354-
);
355-
builder = builder.chunking_config(
356-
Vc::<CssChunkType>::default().to_resolved().await?,
357-
ChunkingConfig {
358-
max_merge_chunk_size: 100_000,
359-
..Default::default()
360-
},
361-
);
362-
builder = builder.use_content_hashing(ContentHashing::Direct { length: 16 })
346+
builder = builder
347+
.chunking_config(
348+
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
349+
ChunkingConfig {
350+
min_chunk_size: 50_000,
351+
max_chunk_count_per_group: 40,
352+
max_merge_chunk_size: 200_000,
353+
..Default::default()
354+
},
355+
)
356+
.chunking_config(
357+
Vc::<CssChunkType>::default().to_resolved().await?,
358+
ChunkingConfig {
359+
max_merge_chunk_size: 100_000,
360+
..Default::default()
361+
},
362+
)
363+
.use_content_hashing(ContentHashing::Direct { length: 16 })
364+
.module_merging(true);
363365
}
364366
}
365367

@@ -387,22 +389,24 @@ async fn build_internal(
387389
match *node_env.await? {
388390
NodeEnv::Development => {}
389391
NodeEnv::Production => {
390-
builder = builder.chunking_config(
391-
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
392-
ChunkingConfig {
393-
min_chunk_size: 20_000,
394-
max_chunk_count_per_group: 100,
395-
max_merge_chunk_size: 100_000,
396-
..Default::default()
397-
},
398-
);
399-
builder = builder.chunking_config(
400-
Vc::<CssChunkType>::default().to_resolved().await?,
401-
ChunkingConfig {
402-
max_merge_chunk_size: 100_000,
403-
..Default::default()
404-
},
405-
);
392+
builder = builder
393+
.chunking_config(
394+
Vc::<EcmascriptChunkType>::default().to_resolved().await?,
395+
ChunkingConfig {
396+
min_chunk_size: 20_000,
397+
max_chunk_count_per_group: 100,
398+
max_merge_chunk_size: 100_000,
399+
..Default::default()
400+
},
401+
)
402+
.chunking_config(
403+
Vc::<CssChunkType>::default().to_resolved().await?,
404+
ChunkingConfig {
405+
max_merge_chunk_size: 100_000,
406+
..Default::default()
407+
},
408+
)
409+
.module_merging(true);
406410
}
407411
}
408412

0 commit comments

Comments
 (0)