Unverified Commit a92da5bc authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Enable constant export inlining for production

Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent d03df269
......@@ -379,7 +379,7 @@ pub async fn get_client_module_options_context(
.await?,
cjs_scope_hoisting: *next_config.turbopack_cjs_scope_hoisting().await?,
cross_module_constants: *next_config.turbopack_cross_module_constants().await?,
inline_constant_exports: *next_config.turbopack_inline_constant_exports().await?,
inline_constant_exports: *next_config.turbopack_inline_constant_exports(mode).await?,
lazy_compilation: *next_config
.turbopack_lazy_dynamic_imports(*next_mode)
.await?,
......
......@@ -1245,7 +1245,8 @@ pub struct ExperimentalConfig {
turbopack_cjs_scope_hoisting: Option<bool>,
/// Enable analyzer-aware cross-module constant inlining. Defaults to false.
turbopack_cross_module_constants: Option<bool>,
/// Inline short constant exports during code generation. Defaults to false.
/// Inline short constant exports during code generation. Defaults to true for production
/// builds and false in development.
turbopack_inline_constant_exports: Option<bool>,
/// Devtool option for the segment explorer.
devtool_segment_explorer: Option<bool>,
......@@ -2406,12 +2407,11 @@ impl NextConfig {
}
#[turbo_tasks::function]
pub fn turbopack_inline_constant_exports(&self) -> Vc<bool> {
Vc::cell(
self.experimental
.turbopack_inline_constant_exports
.unwrap_or(false),
)
pub async fn turbopack_inline_constant_exports(&self, mode: Vc<NextMode>) -> Result<Vc<bool>> {
Ok(Vc::cell(inline_constant_exports_enabled(
self.experimental.turbopack_inline_constant_exports,
*mode.await?,
)))
}
#[turbo_tasks::function]
......@@ -2858,10 +2858,31 @@ pub fn lightningcss_feature_names_to_mask(
Ok(mask.bits())
}
fn inline_constant_exports_enabled(explicit: Option<bool>, mode: NextMode) -> bool {
explicit.unwrap_or(mode.is_production())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_inline_constant_exports_default() {
assert!(inline_constant_exports_enabled(None, NextMode::Build));
assert!(!inline_constant_exports_enabled(
None,
NextMode::Development
));
assert!(!inline_constant_exports_enabled(
Some(false),
NextMode::Build
));
assert!(inline_constant_exports_enabled(
Some(true),
NextMode::Development
));
}
#[test]
fn test_serde_rule_config_item_options() {
let json_value = serde_json::json!({
......
......@@ -552,7 +552,7 @@ pub async fn get_server_module_options_context(
.await?,
cjs_scope_hoisting: *next_config.turbopack_cjs_scope_hoisting().await?,
cross_module_constants: *next_config.turbopack_cross_module_constants().await?,
inline_constant_exports: *next_config.turbopack_inline_constant_exports().await?,
inline_constant_exports: *next_config.turbopack_inline_constant_exports(mode).await?,
..Default::default()
},
execution_context: Some(execution_context),
......
......@@ -1131,7 +1131,7 @@ export interface ExperimentalConfig {
* Inline short, identity-free constant exports during Turbopack code generation without using
* their values for compile-time analysis.
*
* Defaults to `false`
* Defaults to `true` for production builds and `false` in development.
*/
turbopackInlineConstantExports?: boolean
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment