Skip to content

Commit bf62cad

Browse files
committed
feat: support JSX preserve
1 parent 9df8ad7 commit bf62cad

File tree

43 files changed

+1245
-529
lines changed

Some content is hidden

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

43 files changed

+1245
-529
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"devDependencies": {
1515
"@module-federation/rsbuild-plugin": "^0.18.4",
16-
"@rsbuild/core": "1.5.4",
16+
"@rsbuild/core": "1.5.12",
1717
"@rsbuild/plugin-react": "^1.4.0",
1818
"@types/react": "^19.1.12",
1919
"@types/react-dom": "^19.1.9",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"devDependencies": {
1515
"@module-federation/rsbuild-plugin": "^0.18.4",
16-
"@rsbuild/core": "1.5.4",
16+
"@rsbuild/core": "1.5.12",
1717
"@rsbuild/plugin-react": "^1.4.0",
1818
"@types/react": "^19.1.12",
1919
"@types/react-dom": "^19.1.9",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"type-check": "tsc --noEmit && tsc --noEmit -p tests"
4444
},
4545
"dependencies": {
46-
"@rsbuild/core": "1.5.4",
46+
"@rsbuild/core": "1.5.12",
4747
"rsbuild-plugin-dts": "workspace:*",
4848
"tinyglobby": "^0.2.15"
4949
},

packages/core/src/config.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ export function composeMinifyConfig(config: LibConfig): EnvironmentConfig {
392392
js: true,
393393
css: false,
394394
jsOptions: {
395+
// Tweaked based on https://github.com/web-infra-dev/rspack/blob/e350b76163c976ee48da54c29bbb9d72153738d7/crates/rspack_plugin_swc_js_minimizer/src/lib.rs#L40.
396+
test: /\.[cm]?jsx?(\?.*)?$/,
395397
minimizerOptions: {
396398
mangle: false,
397399
// MF assets are loaded over the network, which means they will not be compressed by the project. Therefore, minifying them is necessary.
@@ -833,6 +835,40 @@ const fixJsModuleTypePlugin = (): RsbuildPlugin => ({
833835
},
834836
});
835837

838+
const BundlePlugin = (): RsbuildPlugin => ({
839+
name: 'rslib:bundle',
840+
setup(api) {
841+
api.onBeforeBuild({
842+
order: 'post',
843+
handler: ({ bundlerConfigs }) => {
844+
if (bundlerConfigs) {
845+
for (const config of bundlerConfigs) {
846+
if (config?.module?.parser?.javascript?.jsx === true) {
847+
throw new Error(
848+
'Bundle mode does not support preserving JSX syntax. Set `bundle` to `false` or change the JSX runtime to `automatic` or `classic`.',
849+
);
850+
}
851+
}
852+
}
853+
},
854+
});
855+
},
856+
});
857+
858+
const composeBundleConfig = (
859+
bundle: LibConfig['bundle'],
860+
): { rsbuildConfig: EnvironmentConfig } => {
861+
if (bundle) {
862+
return {
863+
rsbuildConfig: {
864+
plugins: [BundlePlugin()],
865+
},
866+
};
867+
}
868+
869+
return { rsbuildConfig: {} };
870+
};
871+
836872
const composeShimsConfig = (
837873
format: Format,
838874
shims?: Shims,
@@ -1671,6 +1707,7 @@ async function composeLibRsbuildConfig(
16711707
redirect = {},
16721708
umdName,
16731709
} = config;
1710+
const { rsbuildConfig: bundleConfig } = composeBundleConfig(bundle);
16741711
const { rsbuildConfig: shimsConfig, enabledShims } = composeShimsConfig(
16751712
format,
16761713
shims,
@@ -1756,6 +1793,7 @@ async function composeLibRsbuildConfig(
17561793
const printFileSizeConfig = composePrintFileSizeConfig(bundle, target);
17571794

17581795
return mergeRsbuildConfig(
1796+
bundleConfig,
17591797
formatConfig,
17601798
// outputConfig,
17611799
shimsConfig,

packages/create-rslib/fragments/tools/storybook-react-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"storybook": "storybook dev"
55
},
66
"devDependencies": {
7-
"@rsbuild/core": "1.5.4",
7+
"@rsbuild/core": "1.5.12",
88
"@storybook/addon-docs": "^9.1.5",
99
"@storybook/addon-essentials": "^9.0.0-alpha.12",
1010
"@storybook/addon-interactions": "^9.0.0-alpha.10",

packages/create-rslib/fragments/tools/storybook-react-ts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"storybook": "storybook dev"
55
},
66
"devDependencies": {
7-
"@rsbuild/core": "1.5.4",
7+
"@rsbuild/core": "1.5.12",
88
"@storybook/addon-docs": "^9.1.5",
99
"@storybook/addon-essentials": "^9.0.0-alpha.12",
1010
"@storybook/addon-interactions": "^9.0.0-alpha.10",

packages/create-rslib/fragments/tools/storybook-vue-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"storybook": "storybook dev"
55
},
66
"devDependencies": {
7-
"@rsbuild/core": "1.5.4",
7+
"@rsbuild/core": "1.5.12",
88
"@storybook/addon-docs": "^9.1.5",
99
"@storybook/addon-essentials": "^9.0.0-alpha.12",
1010
"@storybook/addon-interactions": "^9.0.0-alpha.10",

packages/create-rslib/fragments/tools/storybook-vue-ts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"storybook": "storybook dev"
55
},
66
"devDependencies": {
7-
"@rsbuild/core": "1.5.4",
7+
"@rsbuild/core": "1.5.12",
88
"@storybook/addon-docs": "^9.1.5",
99
"@storybook/addon-essentials": "^9.0.0-alpha.12",
1010
"@storybook/addon-interactions": "^9.0.0-alpha.10",

packages/create-rslib/template-[react]-[rstest,storybook]-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"test": "rstest"
1919
},
2020
"devDependencies": {
21-
"@rsbuild/core": "1.5.4",
21+
"@rsbuild/core": "1.5.12",
2222
"@rsbuild/plugin-react": "^1.4.0",
2323
"@rslib/core": "workspace:*",
2424
"@rstest/core": "^0.3.3",

packages/create-rslib/template-[react]-[rstest,storybook]-ts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test": "rstest"
2121
},
2222
"devDependencies": {
23-
"@rsbuild/core": "1.5.4",
23+
"@rsbuild/core": "1.5.12",
2424
"@rsbuild/plugin-react": "^1.4.0",
2525
"@rslib/core": "workspace:*",
2626
"@rstest/core": "^0.3.3",

0 commit comments

Comments
 (0)