-
Notifications
You must be signed in to change notification settings - Fork 128
feat(pack): support config.react #2592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,6 +123,7 @@ pub struct Config { | |
| provider: Option<FxIndexMap<RcStr, ProviderConfigValue>>, | ||
| images: Option<ImageConfig>, | ||
| pub styles: Option<StyleConfig>, | ||
| react: Option<ReactConfig>, | ||
| optimization: Option<OptimizationConfig>, | ||
| stats: Option<bool>, | ||
| persistent_caching: Option<bool>, | ||
|
|
@@ -240,6 +241,14 @@ pub struct ExternalAdvanced { | |
| pub sub_path: Option<ExternalSubPath>, | ||
| } | ||
|
|
||
| #[turbo_tasks::value(eq = "manual")] | ||
| #[derive(Clone, Debug, PartialEq, Default, Deserialize, OperationValue)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct ReactConfig { | ||
| /// JSX runtime mode: "automatic" (default) or "classic" | ||
| pub runtime: Option<RcStr>, | ||
| } | ||
|
Comment on lines
+244
to
+250
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better type safety and to provide validation for the You can define a #[turbo_tasks::value]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, OperationValue)]
#[serde(rename_all = "camelCase")]
pub enum JsxRuntime {
Automatic,
Classic,
}
impl JsxRuntime {
pub fn as_str(&self) -> &'static str {
match self {
JsxRuntime::Automatic => "automatic",
JsxRuntime::Classic => "classic",
}
}
}
#[turbo_tasks::value(eq = "manual")]
#[derive(Clone, Debug, PartialEq, Default, Deserialize, OperationValue)]
#[serde(rename_all = "camelCase")]
pub struct ReactConfig {
/// JSX runtime mode: "automatic" (default) or "classic"
pub runtime: Option<JsxRuntime>,
} |
||
|
|
||
| #[turbo_tasks::value(eq = "manual")] | ||
| #[derive(Clone, Debug, PartialEq, Default, Deserialize, OperationValue)] | ||
| #[serde(rename_all = "camelCase")] | ||
|
|
@@ -944,6 +953,11 @@ impl Config { | |
| self.styles.clone().unwrap_or_default().cell() | ||
| } | ||
|
|
||
| #[turbo_tasks::function] | ||
| pub fn react(&self) -> Vc<ReactConfig> { | ||
| self.react.clone().unwrap_or_default().cell() | ||
| } | ||
|
|
||
| #[turbo_tasks::function] | ||
| pub fn output(&self) -> Vc<OutputConfig> { | ||
| self.output.clone().unwrap_or_default().cell() | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -121,13 +121,9 @@ pub async fn get_jsx_transform_options( | |||||
| enable_react_refresh: bool, | ||||||
| ) -> Result<Vc<JsxTransformOptions>> { | ||||||
| let tsconfig = get_typescript_options(project_path.clone()).await?; | ||||||
|
|
||||||
| let is_emotion_enabled = config.styles().await?.emotion.is_some(); | ||||||
| let react_config = config.react().await?; | ||||||
|
|
||||||
| // [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 | ||||||
|
|
@@ -137,7 +133,7 @@ pub async fn get_jsx_transform_options( | |||||
| } else { | ||||||
| None | ||||||
| }, | ||||||
| runtime: Some("automatic".into()), | ||||||
| runtime: react_config.runtime.clone().or(Some("automatic".into())), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To align with the suggested change of using an enum for
Suggested change
|
||||||
| react_refresh: enable_react_refresh, | ||||||
| }; | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,9 @@ | |
| "import": "input/index.js", | ||
| "name": "main" | ||
| } | ||
| ] | ||
| ], | ||
| "react": { | ||
| "runtime": "classic" | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum !