Skip to content

Commit 1a14add

Browse files
committed
chore: update
1 parent b4f52f2 commit 1a14add

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

packages/core/src/config.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,8 @@ const composeAutoExtensionConfig = (
713713
};
714714

715715
const composeSyntaxConfig = (
716+
target: RsbuildConfigOutputTarget,
716717
syntax?: Syntax,
717-
target: RsbuildConfigOutputTarget = 'node',
718718
): RsbuildConfig => {
719719
// Defaults to ESNext, Rslib will assume all of the latest JavaScript and CSS features are supported.
720720
if (syntax) {
@@ -942,30 +942,39 @@ const composeDtsConfig = async (
942942

943943
const composeTargetConfig = (
944944
target: RsbuildConfigOutputTarget = 'node',
945-
): RsbuildConfig => {
945+
): {
946+
config: RsbuildConfig;
947+
target: RsbuildConfigOutputTarget;
948+
} => {
946949
switch (target) {
947950
case 'web':
948951
return {
949-
tools: {
950-
rspack: {
951-
target: ['web'],
952+
config: {
953+
tools: {
954+
rspack: {
955+
target: ['web'],
956+
},
952957
},
953958
},
959+
target: 'web',
954960
};
955961
case 'node':
956962
return {
957-
tools: {
958-
rspack: {
959-
target: ['node'],
963+
config: {
964+
tools: {
965+
rspack: {
966+
target: ['node'],
967+
},
968+
},
969+
output: {
970+
// When output.target is 'node', Node.js's built-in will be treated as externals of type `node-commonjs`.
971+
// Simply override the built-in modules to make them external.
972+
// https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L81
973+
externals: nodeBuiltInModules,
974+
target: 'node',
960975
},
961976
},
962-
output: {
963-
// When output.target is 'node', Node.js's built-in will be treated as externals of type `node-commonjs`.
964-
// Simply override the built-in modules to make them external.
965-
// https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L81
966-
externals: nodeBuiltInModules,
967-
target: 'node',
968-
},
977+
target: 'node',
969978
};
970979
// TODO: Support `neutral` target, however Rsbuild don't list it as an option in the target field.
971980
// case 'neutral':
@@ -1067,11 +1076,10 @@ async function composeLibRsbuildConfig(config: LibConfig, configPath: string) {
10671076
cssModulesAuto,
10681077
bundle,
10691078
);
1070-
const targetConfig = composeTargetConfig(config.output?.target);
1071-
const syntaxConfig = composeSyntaxConfig(
1072-
config?.syntax,
1079+
const { config: targetConfig, target } = composeTargetConfig(
10731080
config.output?.target,
10741081
);
1082+
const syntaxConfig = composeSyntaxConfig(target, config?.syntax);
10751083
const autoExternalConfig = composeAutoExternalConfig({
10761084
autoExternal,
10771085
pkgJson,

0 commit comments

Comments
 (0)