@@ -3,6 +3,8 @@ import path from 'node:path';
3
3
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack' ;
4
4
import { TEMP_DIR } from '@module-federation/sdk' ;
5
5
6
+ import { correctImportPath } from './correctImportPath' ;
7
+
6
8
import type { RsbuildConfig , RsbuildPlugin } from '@rsbuild/core' ;
7
9
import type { moduleFederationPlugin } from '@module-federation/sdk' ;
8
10
@@ -11,14 +13,14 @@ const bootstrapPath = path.resolve(
11
13
process . cwd ( ) ,
12
14
`node_modules/${ TEMP_DIR } /storybook-bootstrap.js` ,
13
15
) ;
14
- const generateBootstrap = ( entryPath : string ) => {
15
- return `import('${ entryPath } ')` ;
16
+ const generateBootstrap = ( context : string , entryPath : string ) => {
17
+ return `import('${ correctImportPath ( context , entryPath ) } '); ` ;
16
18
} ;
17
- const writeBootstrap = ( entryPath : string ) => {
19
+ const writeBootstrap = ( context : string , entryPath : string ) => {
18
20
if ( fs . existsSync ( bootstrapPath ) ) {
19
21
fs . unlinkSync ( bootstrapPath ) ;
20
22
}
21
- fs . writeFileSync ( bootstrapPath , generateBootstrap ( entryPath ) ) ;
23
+ fs . writeFileSync ( bootstrapPath , generateBootstrap ( context , entryPath ) ) ;
22
24
} ;
23
25
export const withModuleFederation = async (
24
26
rsbuildConfig : RsbuildConfig ,
@@ -28,9 +30,10 @@ export const withModuleFederation = async (
28
30
rsbuildConfig . source ??= { } ;
29
31
rsbuildConfig . source . entry ??= { } ;
30
32
const entry = rsbuildConfig . source . entry ;
33
+ const context = rsbuildConfig . root || process . cwd ( ) ;
31
34
for ( const entryName in entry ) {
32
35
if ( Array . isArray ( entry [ entryName ] ) ) {
33
- writeBootstrap ( entry [ entryName ] [ 0 ] ) ;
36
+ writeBootstrap ( context , entry [ entryName ] [ 0 ] ) ;
34
37
entry [ entryName ] = [ bootstrapPath ] ;
35
38
}
36
39
}
0 commit comments