Skip to content
Merged
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
10 changes: 10 additions & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,16 @@ export async function composeCreateRsbuildConfig(
userConfig.output ??= {};
delete userConfig.output.externals;

// Convert output.distPath to an object to ensure it merges correctly with the built-in constant config
if (
userConfig.output.distPath &&
typeof userConfig.output.distPath === 'string'
) {
userConfig.output.distPath = {
root: userConfig.output.distPath,
};
}

const config: RsbuildConfigWithLibInfo = {
format: libConfig.format ?? 'esm',
// The merge order represents the priority of the configuration
Expand Down
45 changes: 45 additions & 0 deletions packages/core/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,51 @@ describe('Should compose create Rsbuild config correctly', () => {
expect(rsbuildConfig).toMatchSnapshot('inspected Rsbuild configs');
expect(bundlerConfigs).toMatchSnapshot('inspected Rspack configs');
});

test('Merge output.distPath correctly', async () => {
const rslibConfig: RslibConfig = {
lib: [
{
format: 'esm',
output: {
distPath: 'dist/esm',
},
},
{
format: 'cjs',
output: {
distPath: {
root: 'dist/cjs',
},
},
},
],
};

const composedRsbuildConfig = await composeCreateRsbuildConfig(rslibConfig);
expect(
composedRsbuildConfig[0]?.config.output?.distPath,
).toMatchInlineSnapshot(`
{
"css": "./",
"cssAsync": "./",
"js": "./",
"jsAsync": "./",
"root": "dist/esm",
}
`);
expect(
composedRsbuildConfig[1]?.config.output?.distPath,
).toMatchInlineSnapshot(`
{
"css": "./",
"cssAsync": "./",
"js": "./",
"jsAsync": "./",
"root": "dist/cjs",
}
`);
});
});

describe('syntax', () => {
Expand Down
Loading