Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions crates/pack-core/src/client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ pub async fn get_client_module_options_context(
} else {
false
};
let jsx_runtime_options = get_jsx_transform_options(
let jsx_transform_options = get_jsx_transform_options(
project_path.clone(),
mode,
false,
Expand All @@ -300,7 +300,6 @@ pub async fn get_client_module_options_context(

let foreign_enable_webpack_loaders =
*webpack_loader_options(project_path.clone(), config, foreign_conditions).await?;

// Now creates a webpack rules that applies to all codes.
let enable_webpack_loaders =
*webpack_loader_options(project_path.clone(), config, loader_conditions).await?;
Expand Down Expand Up @@ -378,10 +377,6 @@ pub async fn get_client_module_options_context(
enable_typeof_window_inlining: Some(TypeofWindow::Object),
source_maps,
import_externals: *config.import_externals().await?,
enable_typescript_transform: Some(
TypescriptTransformOptions::default().resolved_cell(),
),
enable_jsx: Some(JsxTransformOptions::default().resolved_cell()),
ignore_dynamic_requests: true,
..Default::default()
},
Expand All @@ -406,6 +401,8 @@ pub async fn get_client_module_options_context(
let foreign_codes_options_context = ModuleOptionsContext {
ecmascript: EcmascriptOptionsContext {
enable_typeof_window_inlining: None,
enable_jsx: Some(jsx_transform_options),
enable_typescript_transform: Some(tsconfig),
..module_options_context.ecmascript

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这不对吧?foreign codes 应该用自己包内的 tsconfig ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个之前都是不会读的,走默认的

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

},
enable_webpack_loaders: foreign_enable_webpack_loaders,
Expand All @@ -417,6 +414,10 @@ pub async fn get_client_module_options_context(

let internal_context = ModuleOptionsContext {
ecmascript: EcmascriptOptionsContext {
enable_typescript_transform: Some(
TypescriptTransformOptions::default().resolved_cell(),
),
enable_jsx: Some(JsxTransformOptions::default().resolved_cell()),
..module_options_context.ecmascript.clone()
},
enable_postcss_transform: None,
Expand All @@ -428,7 +429,7 @@ pub async fn get_client_module_options_context(
// we try resolve it once at the root and pass down a context to all
// the modules.
ecmascript: EcmascriptOptionsContext {
enable_jsx: Some(jsx_runtime_options),
enable_jsx: Some(jsx_transform_options),
enable_typescript_transform: Some(tsconfig),
enable_decorators: Some(decorators_options.to_resolved().await?),
..module_options_context.ecmascript.clone()
Expand Down
15 changes: 11 additions & 4 deletions crates/pack-core/src/transform_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ pub async fn get_jsx_transform_options(

let is_emotion_enabled = config.styles().await?.emotion.is_some();

// [NOTE]: ref: WEB-901
// next.js does not allow to overriding react runtime config via tsconfig /
// jsconfig, it forces overrides into automatic runtime instead.
// [TODO]: we need to emit / validate config message like next.js devserver does
let react_transform_options = JsxTransformOptions {
development: mode.await?.is_react_development(),
// https://github.com/vercel/next.js/blob/3dc2c1c7f8441cdee31da9f7e0986d654c7fd2e7/packages/next/src/build/swc/options.ts#L112
Expand All @@ -147,12 +143,23 @@ pub async fn get_jsx_transform_options(
.as_str()
.map(|s| s.into());

// Map TypeScript jsx compiler option to JSX runtime
// TypeScript jsx values: "react" -> classic, "react-jsx" | "react-jsxdev" -> automatic
let jsx_runtime = json["compilerOptions"]["jsx"]
.as_str()
.and_then(|jsx| match jsx {
"react" => Some("classic".into()),
"react-jsx" | "react-jsxdev" => Some("automatic".into()),
_ => None,
});

Some(JsxTransformOptions {
import_source: if jsx_import_source.is_some() {
jsx_import_source
} else {
react_transform_options.import_source.clone()
},
runtime: jsx_runtime.or_else(|| react_transform_options.runtime.clone()),
..react_transform_options.clone()
})
Comment thread
fireairforce marked this conversation as resolved.
Resolved
})
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"jsx": "react",
}
}
Loading