Unverified Commit fae94416 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Move modularize imports for next/server to next-swc (#47788)

Follow up for #47715 

Moving modularize imports handlign for next/server into `next-swc` side
parent 90ac02f7
...@@ -153,6 +153,21 @@ where ...@@ -153,6 +153,21 @@ where
} }
}; };
let mut modularize_imports_config = match &opts.modularize_imports {
Some(config) => config.clone(),
None => turbo_binding::swc::custom_transform::modularize_imports::Config {
packages: std::collections::HashMap::new(),
},
};
modularize_imports_config.packages.insert(
"next/server".to_string(),
turbo_binding::swc::custom_transform::modularize_imports::PackageConfig {
transform: "next/dist/server/web/exports/{{ kebabCase member }}".to_string(),
prevent_full_import: false,
skip_default_conversion: false,
},
);
chain!( chain!(
disallow_re_export_all_in_page::disallow_re_export_all_in_page(opts.is_page_file), disallow_re_export_all_in_page::disallow_re_export_all_in_page(opts.is_page_file),
match &opts.server_components { match &opts.server_components {
...@@ -244,14 +259,9 @@ where ...@@ -244,14 +259,9 @@ where
} }
}) })
.unwrap_or_else(|| Either::Right(noop())), .unwrap_or_else(|| Either::Right(noop())),
match &opts.modularize_imports { turbo_binding::swc::custom_transform::modularize_imports::modularize_imports(
Some(config) => Either::Left( modularize_imports_config
turbo_binding::swc::custom_transform::modularize_imports::modularize_imports( ),
config.clone()
)
),
None => Either::Right(noop()),
},
match &opts.font_loaders { match &opts.font_loaders {
Some(config) => Either::Left(next_font_loaders(config.clone())), Some(config) => Either::Left(next_font_loaders(config.clone())),
None => Either::Right(noop()), None => Either::Right(noop()),
......
...@@ -50,14 +50,6 @@ function getBaseSWCOptions({ ...@@ -50,14 +50,6 @@ function getBaseSWCOptions({
.filter(Array.isArray) .filter(Array.isArray)
.map(([name, options]: any) => [require.resolve(name), options]) .map(([name, options]: any) => [require.resolve(name), options])
// Use modularized imports for next/server to ensure treeshaking.
// This prevents ImageResponse related assets from being bundled when not used.
// TODO: move it into next-swc
const modularizeImports = nextConfig?.modularizeImports || {}
modularizeImports['next/server'] = {
transform: 'next/dist/server/web/exports/{{ kebabCase member }}',
}
return { return {
jsc: { jsc: {
...(resolvedBaseUrl && paths ...(resolvedBaseUrl && paths
...@@ -123,7 +115,7 @@ function getBaseSWCOptions({ ...@@ -123,7 +115,7 @@ function getBaseSWCOptions({
reactRemoveProperties: jest reactRemoveProperties: jest
? false ? false
: nextConfig?.compiler?.reactRemoveProperties, : nextConfig?.compiler?.reactRemoveProperties,
modularizeImports, modularizeImports: nextConfig?.modularizeImports,
relay: nextConfig?.compiler?.relay, relay: nextConfig?.compiler?.relay,
// Always transform styled-jsx and error when `client-only` condition is triggered // Always transform styled-jsx and error when `client-only` condition is triggered
styledJsx: true, styledJsx: true,
......
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