From 03f2fd4b351a273675a3b2e9987433b86d482712 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Tue, 27 Aug 2024 17:50:53 +0800 Subject: [PATCH 1/3] feat: modify merge config order --- packages/core/src/config.ts | 12 +- .../tests/__snapshots__/config.test.ts.snap | 118 +++++++++--------- packages/core/tests/config.test.ts | 1 - 3 files changed, 67 insertions(+), 64 deletions(-) diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index b8c929741..feaff6e03 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -660,7 +660,15 @@ export async function composeCreateRsbuildConfig( return { format: libConfig.format!, + // The merge order represents the priority of the configuration + // The priorities from high to low are as follows: + // 1 - userConfig: users can configure any Rsbuild and Rspack config + // 2 - libRsbuildConfig: the configuration that we compose from Rslib unique config and userConfig from 1 + // 3 - internalRsbuildConfig: the built-in best practice Rsbuild configuration we provide in Rslib + // We should state in the document that the built-in configuration should not be changed optionally config: mergeRsbuildConfig( + internalRsbuildConfig, + libRsbuildConfig, omitDeep(userConfig, [ 'bundle', 'format', @@ -669,10 +677,6 @@ export async function composeCreateRsbuildConfig( 'syntax', 'dts', ]), - libRsbuildConfig, - // Merge order matters, keep `internalRsbuildConfig` at the last position - // to ensure that the internal config is not overridden by user's config. - internalRsbuildConfig, ), }; }); diff --git a/packages/core/tests/__snapshots__/config.test.ts.snap b/packages/core/tests/__snapshots__/config.test.ts.snap index f975d2197..64b5c6a71 100644 --- a/packages/core/tests/__snapshots__/config.test.ts.snap +++ b/packages/core/tests/__snapshots__/config.test.ts.snap @@ -59,35 +59,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 "tools": { "htmlPlugin": false, "rspack": [ - { - "experiments": { - "outputModule": true, - }, - "externalsType": "module-import", - "module": { - "parser": { - "javascript": { - "importMeta": false, - }, - }, - }, - "optimization": { - "concatenateModules": true, - }, - "output": { - "chunkFormat": "module", - "library": { - "type": "modern-module", - }, - "module": true, - }, - }, - [Function], - { - "target": [ - "web", - ], - }, { "experiments": { "rspackFuture": { @@ -122,6 +93,35 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 }, }, }, + { + "experiments": { + "outputModule": true, + }, + "externalsType": "module-import", + "module": { + "parser": { + "javascript": { + "importMeta": false, + }, + }, + }, + "optimization": { + "concatenateModules": true, + }, + "output": { + "chunkFormat": "module", + "library": { + "type": "modern-module", + }, + "module": true, + }, + }, + [Function], + { + "target": [ + "web", + ], + }, ], }, }, @@ -185,22 +185,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 "tools": { "htmlPlugin": false, "rspack": [ - { - "externalsType": "commonjs", - "output": { - "chunkFormat": "commonjs", - "iife": false, - "library": { - "type": "commonjs", - }, - }, - }, - [Function], - { - "target": [ - "web", - ], - }, { "experiments": { "rspackFuture": { @@ -235,6 +219,22 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 }, }, }, + { + "externalsType": "commonjs", + "output": { + "chunkFormat": "commonjs", + "iife": false, + "library": { + "type": "commonjs", + }, + }, + }, + [Function], + { + "target": [ + "web", + ], + }, ], }, }, @@ -294,20 +294,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 "tools": { "htmlPlugin": false, "rspack": [ - { - "externalsType": "umd", - "output": { - "library": { - "type": "umd", - }, - }, - }, - [Function], - { - "target": [ - "web", - ], - }, { "experiments": { "rspackFuture": { @@ -342,6 +328,20 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 }, }, }, + { + "externalsType": "umd", + "output": { + "library": { + "type": "umd", + }, + }, + }, + [Function], + { + "target": [ + "web", + ], + }, ], }, }, diff --git a/packages/core/tests/config.test.ts b/packages/core/tests/config.test.ts index a0cd842ac..493ea09a6 100644 --- a/packages/core/tests/config.test.ts +++ b/packages/core/tests/config.test.ts @@ -178,7 +178,6 @@ describe('Should compose create Rsbuild config correctly', () => { }, output: { filenameHash: false, - minify: true, }, }; const composedRsbuildConfig = await composeCreateRsbuildConfig( From f6f03c1647f786167c3dd8e816fd0e55410a63eb Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Tue, 27 Aug 2024 17:54:10 +0800 Subject: [PATCH 2/3] chore: update --- packages/core/src/config.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index feaff6e03..a302a7ff3 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -666,6 +666,8 @@ export async function composeCreateRsbuildConfig( // 2 - libRsbuildConfig: the configuration that we compose from Rslib unique config and userConfig from 1 // 3 - internalRsbuildConfig: the built-in best practice Rsbuild configuration we provide in Rslib // We should state in the document that the built-in configuration should not be changed optionally + // In compose process of 2, we may read some config from 1, and reassemble the related config, + // so before final mergeRsbuildConfig, we reset some specified fields config: mergeRsbuildConfig( internalRsbuildConfig, libRsbuildConfig, From 68b51e83ebaf09ab7f190923958874eddc037272 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Tue, 27 Aug 2024 18:00:11 +0800 Subject: [PATCH 3/3] chore: update --- .../tests/__snapshots__/config.test.ts.snap | 30 +++++++++++++++++++ packages/core/tests/config.test.ts | 9 ++++++ 2 files changed, 39 insertions(+) diff --git a/packages/core/tests/__snapshots__/config.test.ts.snap b/packages/core/tests/__snapshots__/config.test.ts.snap index 64b5c6a71..8955e14f1 100644 --- a/packages/core/tests/__snapshots__/config.test.ts.snap +++ b/packages/core/tests/__snapshots__/config.test.ts.snap @@ -122,6 +122,16 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 "web", ], }, + { + "resolve": { + "extensionAlias": { + ".js": [ + ".ts", + ".tsx", + ], + }, + }, + }, ], }, }, @@ -235,6 +245,16 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 "web", ], }, + { + "resolve": { + "extensionAlias": { + ".js": [ + ".ts", + ".tsx", + ], + }, + }, + }, ], }, }, @@ -342,6 +362,16 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 "web", ], }, + { + "resolve": { + "extensionAlias": { + ".js": [ + ".ts", + ".tsx", + ], + }, + }, + }, ], }, }, diff --git a/packages/core/tests/config.test.ts b/packages/core/tests/config.test.ts index 493ea09a6..f099c72ed 100644 --- a/packages/core/tests/config.test.ts +++ b/packages/core/tests/config.test.ts @@ -179,6 +179,15 @@ describe('Should compose create Rsbuild config correctly', () => { output: { filenameHash: false, }, + tools: { + rspack: { + resolve: { + extensionAlias: { + '.js': ['.ts', '.tsx'], + }, + }, + }, + }, }; const composedRsbuildConfig = await composeCreateRsbuildConfig( rslibConfig,