Skip to content

Commit 662a820

Browse files
nyqykk2heal1
andauthored
feat: support storybook dev remote app in rsbuild(rslib) project (#3131)
Co-authored-by: 2heal1 <[email protected]>
1 parent c5df209 commit 662a820

26 files changed

+1247
-227
lines changed

.changeset/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"@module-federation/modern-js",
2323
"@module-federation/retry-plugin",
2424
"@module-federation/data-prefetch",
25-
"@module-federation/rsbuild-plugin"
25+
"@module-federation/rsbuild-plugin",
26+
"@module-federation/storybook-addon"
2627
]
2728
],
2829
"ignorePatterns": ["^alpha|^beta"],

.changeset/mean-jokes-remember.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
'@module-federation/storybook-addon': patch
3+
---
4+
feat: support storybook dev remote app in rsbuild(rslib) project [#3131](https://github.com/module-federation/core/pull/3131)

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ migrations.json
4949
packages/**/dist
5050
apps/**/dist
5151

52-
**/@mf-types
5352
**/@mf-types/**
5453
**/cypress/downloads
5554

@@ -67,3 +66,6 @@ packages/enhanced/test/js
6766
**/dist-test/**
6867
**/cypress/downloads
6968
/packages/data-prefetch/jest/cache/
69+
70+
# storybook cases
71+
!apps/rslib-module/@mf-types/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { dirname, join } from 'node:path';
2+
import type { StorybookConfig } from 'storybook-react-rsbuild';
3+
4+
/**
5+
* This function is used to resolve the absolute path of a package.
6+
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
7+
*/
8+
function getAbsolutePath(value: string): any {
9+
return dirname(require.resolve(join(value, 'package.json')));
10+
}
11+
12+
const config: StorybookConfig = {
13+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
14+
framework: {
15+
name: getAbsolutePath('storybook-react-rsbuild'),
16+
options: {},
17+
},
18+
addons: [
19+
{
20+
name: '@module-federation/storybook-addon/preset.js',
21+
options: {
22+
remotes: {
23+
'rslib-module':
24+
'rslib-module@http://localhost:3000/mf/mf-manifest.json',
25+
},
26+
shareStrategy: 'loaded-first',
27+
},
28+
},
29+
],
30+
};
31+
32+
export default config;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type {
2+
PackageType as PackageType_0,
3+
RemoteKeys as RemoteKeys_0,
4+
} from './rslib-module/apis.d.ts';
5+
declare module '@module-federation/runtime' {
6+
type RemoteKeys = RemoteKeys_0;
7+
type PackageType<T, Y = any> = T extends RemoteKeys_0 ? PackageType_0<T> : Y;
8+
export function loadRemote<T extends RemoteKeys, Y>(
9+
packageName: T,
10+
): Promise<PackageType<T, Y>>;
11+
export function loadRemote<T extends string, Y>(
12+
packageName: T,
13+
): Promise<PackageType<T, Y>>;
14+
}
15+
declare module '@module-federation/enhanced/runtime' {
16+
type RemoteKeys = RemoteKeys_0;
17+
type PackageType<T, Y = any> = T extends RemoteKeys_0 ? PackageType_0<T> : Y;
18+
export function loadRemote<T extends RemoteKeys, Y>(
19+
packageName: T,
20+
): Promise<PackageType<T, Y>>;
21+
export function loadRemote<T extends string, Y>(
22+
packageName: T,
23+
): Promise<PackageType<T, Y>>;
24+
}
25+
declare module '@module-federation/runtime-tools' {
26+
type RemoteKeys = RemoteKeys_0;
27+
type PackageType<T, Y = any> = T extends RemoteKeys_0 ? PackageType_0<T> : Y;
28+
export function loadRemote<T extends RemoteKeys, Y>(
29+
packageName: T,
30+
): Promise<PackageType<T, Y>>;
31+
export function loadRemote<T extends string, Y>(
32+
packageName: T,
33+
): Promise<PackageType<T, Y>>;
34+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export type RemoteKeys = 'rslib-module';
2+
type PackageType<T> = T extends 'rslib-module'
3+
? typeof import('rslib-module')
4+
: any;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface CounterButtonProps {
2+
onClick: () => void;
3+
label: string;
4+
[key: string]: any;
5+
}
6+
export declare const CounterButton: React.FC<CounterButtonProps>;
7+
export {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare const Counter: React.FC;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export declare const useCounter: (initialValue?: number) => {
2+
count: number;
3+
increment: () => void;
4+
decrement: () => void;
5+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './compiled-types/index';
2+
export { default } from './compiled-types/index';

0 commit comments

Comments
 (0)