Skip to content

Commit 28ed0fc

Browse files
committed
feat: support JSX preserve
1 parent 4cd0981 commit 28ed0fc

File tree

44 files changed

+1095
-274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1095
-274
lines changed

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"**",
2222
"!**/*.vue",
2323
"!**/.rslib/**/*",
24-
"!tests/e2e/react-component/public/umd/**/*"
24+
"!tests/e2e/react-component/public/umd/**/*",
25+
"!tests/integration/preserve-jsx/default/src/Component2.tsx"
2526
],
2627
"indentStyle": "space"
2728
},

examples/module-federation/mf-host/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"devDependencies": {
1515
"@module-federation/rsbuild-plugin": "^0.19.1",
1616
"@rsbuild/core": "~1.5.11",
17-
"@rsbuild/plugin-react": "^1.4.0",
17+
"@rsbuild/plugin-react": "^1.4.1",
1818
"@types/react": "^19.1.13",
1919
"@types/react-dom": "^19.1.9",
2020
"typescript": "^5.9.2"

examples/module-federation/mf-react-component/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@module-federation/enhanced": "^0.19.1",
2222
"@module-federation/rsbuild-plugin": "^0.19.1",
2323
"@module-federation/storybook-addon": "^4.0.30",
24-
"@rsbuild/plugin-react": "^1.4.0",
24+
"@rsbuild/plugin-react": "^1.4.1",
2525
"@rslib/core": "workspace:*",
2626
"@types/react": "^19.1.13",
2727
"http-server": "^14.1.1",

examples/module-federation/mf-remote/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"devDependencies": {
1515
"@module-federation/rsbuild-plugin": "^0.19.1",
1616
"@rsbuild/core": "~1.5.11",
17-
"@rsbuild/plugin-react": "^1.4.0",
17+
"@rsbuild/plugin-react": "^1.4.1",
1818
"@types/react": "^19.1.13",
1919
"@types/react-dom": "^19.1.9",
2020
"typescript": "^5.9.2"

examples/react-component-bundle-false/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "rslib build"
99
},
1010
"devDependencies": {
11-
"@rsbuild/plugin-react": "^1.4.0",
11+
"@rsbuild/plugin-react": "^1.4.1",
1212
"@rsbuild/plugin-sass": "^1.4.0",
1313
"@rslib/core": "workspace:*",
1414
"@types/react": "^19.1.13",

examples/react-component-bundle/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "rslib build"
99
},
1010
"devDependencies": {
11-
"@rsbuild/plugin-react": "^1.4.0",
11+
"@rsbuild/plugin-react": "^1.4.1",
1212
"@rsbuild/plugin-sass": "^1.4.0",
1313
"@rslib/core": "workspace:*",
1414
"@types/react": "^19.1.13",

examples/react-component-umd/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build": "rslib build"
88
},
99
"devDependencies": {
10-
"@rsbuild/plugin-react": "^1.4.0",
10+
"@rsbuild/plugin-react": "^1.4.1",
1111
"@rsbuild/plugin-sass": "^1.4.0",
1212
"@rslib/core": "workspace:*",
1313
"@types/react": "^19.1.13",

packages/core/src/config.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ export function composeMinifyConfig(config: LibConfig): EnvironmentConfig {
397397
js: true,
398398
css: false,
399399
jsOptions: {
400+
// Tweaked based on https://github.com/web-infra-dev/rspack/blob/e350b76163c976ee48da54c29bbb9d72153738d7/crates/rspack_plugin_swc_js_minimizer/src/lib.rs#L40.
401+
test: /\.[cm]?jsx?(\?.*)?$/,
400402
minimizerOptions: {
401403
mangle: false,
402404
// MF assets are loaded over the network, which means they will not be compressed by the project. Therefore, minifying them is necessary.
@@ -838,6 +840,40 @@ const fixJsModuleTypePlugin = (): RsbuildPlugin => ({
838840
},
839841
});
840842

843+
const BundlePlugin = (): RsbuildPlugin => ({
844+
name: 'rslib:bundle',
845+
setup(api) {
846+
api.onBeforeBuild({
847+
order: 'post',
848+
handler: ({ bundlerConfigs }) => {
849+
if (bundlerConfigs) {
850+
for (const config of bundlerConfigs) {
851+
if (config?.module?.parser?.javascript?.jsx === true) {
852+
throw new Error(
853+
'Bundle mode does not support preserving JSX syntax. Set `bundle` to `false` or change the JSX runtime to `automatic` or `classic`.',
854+
);
855+
}
856+
}
857+
}
858+
},
859+
});
860+
},
861+
});
862+
863+
const composeBundleConfig = (
864+
bundle: LibConfig['bundle'],
865+
): { rsbuildConfig: EnvironmentConfig } => {
866+
if (bundle) {
867+
return {
868+
rsbuildConfig: {
869+
plugins: [BundlePlugin()],
870+
},
871+
};
872+
}
873+
874+
return { rsbuildConfig: {} };
875+
};
876+
841877
const composeShimsConfig = (
842878
format: Format,
843879
shims?: Shims,
@@ -1676,6 +1712,7 @@ async function composeLibRsbuildConfig(
16761712
redirect = {},
16771713
umdName,
16781714
} = config;
1715+
const { rsbuildConfig: bundleConfig } = composeBundleConfig(bundle);
16791716
const { rsbuildConfig: shimsConfig, enabledShims } = composeShimsConfig(
16801717
format,
16811718
shims,
@@ -1761,6 +1798,7 @@ async function composeLibRsbuildConfig(
17611798
const printFileSizeConfig = composePrintFileSizeConfig(bundle, target);
17621799

17631800
return mergeRsbuildConfig(
1801+
bundleConfig,
17641802
formatConfig,
17651803
// outputConfig,
17661804
shimsConfig,

packages/create-rslib/fragments/base/react-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"dev": "rslib build --watch"
1616
},
1717
"devDependencies": {
18-
"@rsbuild/plugin-react": "^1.4.0",
18+
"@rsbuild/plugin-react": "^1.4.1",
1919
"@rslib/core": "workspace:*",
2020
"react": "^19.1.1"
2121
},

packages/create-rslib/fragments/base/react-ts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"dev": "rslib build --watch"
1818
},
1919
"devDependencies": {
20-
"@rsbuild/plugin-react": "^1.4.0",
20+
"@rsbuild/plugin-react": "^1.4.1",
2121
"@rslib/core": "workspace:*",
2222
"@types/react": "^19.1.13",
2323
"react": "^19.1.1",

0 commit comments

Comments
 (0)