Skip to content

Commit 731517b

Browse files
Merge branch 'main' into share-filter
2 parents c5b7b0b + d237ab9 commit 731517b

File tree

5 files changed

+238
-38
lines changed

5 files changed

+238
-38
lines changed

.changeset/nervous-cougars-heal.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/rsbuild-plugin': patch
3+
---
4+
5+
fix(rsbuild-plugin): detect server.cors option to check waring

.changeset/nice-windows-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/rsbuild-plugin': patch
3+
---
4+
5+
fix(rsbuild-plugin): judge options from orignal userConfig

packages/rsbuild-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@module-federation/enhanced": "workspace:*"
4545
},
4646
"devDependencies": {
47-
"@rsbuild/core": "^1.0.19"
47+
"@rsbuild/core": "^1.3.17"
4848
},
4949
"peerDependencies": {
5050
"@rsbuild/core": "1.x"

packages/rsbuild-plugin/src/cli/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,26 @@ export const pluginModuleFederation = (
178178
if (moduleFederationOptions.exposes) {
179179
config.dev ||= {};
180180
config.server ||= {};
181+
const userConfig = api.getRsbuildConfig('original');
181182

182183
// Allow remote modules to be loaded by setting CORS headers
183184
// This is required for MF to work properly across different origins
184185
config.server.headers ||= {};
185-
if (!config.server.headers['Access-Control-Allow-Origin']) {
186+
if (
187+
!config.server.headers['Access-Control-Allow-Origin'] &&
188+
!(
189+
typeof userConfig.server?.cors === 'object' &&
190+
userConfig.server.cors.origin
191+
)
192+
) {
186193
const corsWarnMsgs = [
187-
'Detect devServer.headers is empty, mf modern plugin will add default cors header: devServer.headers["Access-Control-Allow-Headers"] = "*". It is recommended to specify an allowlist of trusted origins instead.',
194+
'Detect that CORS options are not set, mf Rsbuild plugin will add default cors header: server.headers["Access-Control-Allow-Headers"] = "*". It is recommended to specify an allowlist of trusted origins in "server.cors" instead.',
188195
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.',
189196
];
190197

191198
logger.warn(corsWarnMsgs.join('\n'));
199+
config.server.headers['Access-Control-Allow-Origin'] = '*';
192200
}
193-
config.server.headers['Access-Control-Allow-Origin'] ||= '*';
194201

195202
// For remote modules, Rsbuild should send the ws request to the provider's dev server.
196203
// This allows the provider to do HMR when the provider module is loaded in the consumer's page.

0 commit comments

Comments
 (0)