@@ -2,7 +2,7 @@ import { parseOptions } from '@module-federation/enhanced';
2
2
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack' ;
3
3
import { isRequiredVersion } from '@module-federation/sdk' ;
4
4
5
- import { isRegExp } from '../utils/index' ;
5
+ import { isRegExp , DEFAULT_ASSET_PREFIX } from '../utils/index' ;
6
6
import pkgJson from '../../package.json' ;
7
7
8
8
import type {
@@ -44,16 +44,26 @@ export const pluginModuleFederation = (
44
44
) ;
45
45
46
46
api . modifyRsbuildConfig ( ( config ) => {
47
- // If this is a provider app, Rsbuild should send the ws request to the provider's dev server.
48
- // This allows the provider to do HMR when the provider module is loaded in the consumer's page.
49
- if (
50
- moduleFederationOptions . exposes &&
51
- config . server ?. port &&
52
- ! config . dev ?. client ?. port
53
- ) {
47
+ // Change some default configs for remote modules
48
+ if ( moduleFederationOptions . exposes ) {
54
49
config . dev ||= { } ;
55
- config . dev . client ||= { } ;
56
- config . dev . client . port = config . server . port ;
50
+
51
+ // For remote modules, Rsbuild should send the ws request to the provider's dev server.
52
+ // This allows the provider to do HMR when the provider module is loaded in the consumer's page.
53
+ if ( config . server ?. port && ! config . dev . client ?. port ) {
54
+ config . dev . client ||= { } ;
55
+ config . dev . client . port = config . server . port ;
56
+ }
57
+
58
+ // Change the default assetPrefix to `true` for remote modules.
59
+ // This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
60
+ const originalConfig = api . getRsbuildConfig ( 'original' ) ;
61
+ if (
62
+ originalConfig . dev ?. assetPrefix === undefined &&
63
+ config . dev . assetPrefix === DEFAULT_ASSET_PREFIX
64
+ ) {
65
+ config . dev . assetPrefix = true ;
66
+ }
57
67
}
58
68
} ) ;
59
69
@@ -147,12 +157,6 @@ export const pluginModuleFederation = (
147
157
if ( ! chain . output . get ( 'uniqueName' ) ) {
148
158
chain . output . set ( 'uniqueName' , moduleFederationOptions . name ) ;
149
159
}
150
-
151
- const publicPath = chain . output . get ( 'publicPath' ) ;
152
- // set the default publicPath to 'auto' to make MF work
153
- if ( publicPath === '/' ) {
154
- chain . output . set ( 'publicPath' , 'auto' ) ;
155
- }
156
160
} ) ;
157
161
} ,
158
162
} ) ;
0 commit comments