-
-
Notifications
You must be signed in to change notification settings - Fork 375
feat: support storybook dev remote app in rsbuild(rslib) project #3131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dcc67e8
feat: support storybook dev in rsbuild project
nyqykk 00d55e0
Merge branch 'main' into chore/storybook-addon
nyqykk 24aba09
chore: add changeset
nyqykk 615254d
fix: add preset into build asset
nyqykk 8e4e3eb
docs: add readme
nyqykk 722d4ca
chore: solve conversation issues
nyqykk 48ae0a6
chore: add lib mf types into git
nyqykk 97059c3
Merge branch 'main' into chore/storybook-addon
nyqykk 6d29c64
chore: modify readme
nyqykk ee3bafd
chore: add readme
2heal1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| '@module-federation/storybook-addon': patch | ||
| --- | ||
| feat: support storybook dev remote app in rsbuild(rslib) project [#3131](https://github.com/module-federation/core/pull/3131) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { dirname, join } from 'node:path'; | ||
| import type { StorybookConfig } from 'storybook-react-rsbuild'; | ||
|
|
||
| /** | ||
| * This function is used to resolve the absolute path of a package. | ||
| * It is needed in projects that use Yarn PnP or are set up within a monorepo. | ||
| */ | ||
| function getAbsolutePath(value: string): any { | ||
| return dirname(require.resolve(join(value, 'package.json'))); | ||
| } | ||
|
|
||
| const config: StorybookConfig = { | ||
| stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'], | ||
| framework: { | ||
| name: getAbsolutePath('storybook-react-rsbuild'), | ||
| options: {}, | ||
| }, | ||
| addons: [ | ||
| { | ||
| name: '@module-federation/storybook-addon/preset.js', | ||
| options: { | ||
| remotes: { | ||
| 'rslib-module': | ||
| 'rslib-module@http://localhost:3000/mf/mf-manifest.json', | ||
| }, | ||
| shareStrategy: 'loaded-first', | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { | ||
| PackageType as PackageType_0, | ||
| RemoteKeys as RemoteKeys_0, | ||
| } from './rslib-module/apis.d.ts'; | ||
| declare module '@module-federation/runtime' { | ||
| type RemoteKeys = RemoteKeys_0; | ||
| type PackageType<T, Y = any> = T extends RemoteKeys_0 ? PackageType_0<T> : Y; | ||
| export function loadRemote<T extends RemoteKeys, Y>( | ||
| packageName: T, | ||
| ): Promise<PackageType<T, Y>>; | ||
| export function loadRemote<T extends string, Y>( | ||
| packageName: T, | ||
| ): Promise<PackageType<T, Y>>; | ||
| } | ||
| declare module '@module-federation/enhanced/runtime' { | ||
| type RemoteKeys = RemoteKeys_0; | ||
| type PackageType<T, Y = any> = T extends RemoteKeys_0 ? PackageType_0<T> : Y; | ||
| export function loadRemote<T extends RemoteKeys, Y>( | ||
| packageName: T, | ||
| ): Promise<PackageType<T, Y>>; | ||
| export function loadRemote<T extends string, Y>( | ||
| packageName: T, | ||
| ): Promise<PackageType<T, Y>>; | ||
| } | ||
| declare module '@module-federation/runtime-tools' { | ||
| type RemoteKeys = RemoteKeys_0; | ||
| type PackageType<T, Y = any> = T extends RemoteKeys_0 ? PackageType_0<T> : Y; | ||
| export function loadRemote<T extends RemoteKeys, Y>( | ||
| packageName: T, | ||
| ): Promise<PackageType<T, Y>>; | ||
| export function loadRemote<T extends string, Y>( | ||
| packageName: T, | ||
| ): Promise<PackageType<T, Y>>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export type RemoteKeys = 'rslib-module'; | ||
| type PackageType<T> = T extends 'rslib-module' | ||
| ? typeof import('rslib-module') | ||
| : any; |
7 changes: 7 additions & 0 deletions
7
apps/rslib-module/@mf-types/rslib-module/compiled-types/CounterButton.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| interface CounterButtonProps { | ||
| onClick: () => void; | ||
| label: string; | ||
| [key: string]: any; | ||
| } | ||
| export declare const CounterButton: React.FC<CounterButtonProps>; | ||
| export {}; |
1 change: 1 addition & 0 deletions
1
apps/rslib-module/@mf-types/rslib-module/compiled-types/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export declare const Counter: React.FC; |
5 changes: 5 additions & 0 deletions
5
apps/rslib-module/@mf-types/rslib-module/compiled-types/useCounter.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export declare const useCounter: (initialValue?: number) => { | ||
| count: number; | ||
| increment: () => void; | ||
| decrement: () => void; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './compiled-types/index'; | ||
| export { default } from './compiled-types/index'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # @examples/mf-react-component | ||
|
|
||
| This example demonstrates how to use Rslib to build a simple Module Federation React component. | ||
|
|
||
| ### Command | ||
|
|
||
| Build package | ||
|
|
||
| ``` | ||
| nx build rslib-module | ||
| ``` | ||
|
|
||
| Serve package | ||
|
|
||
| ``` | ||
| nx serve rslib-module | ||
| ``` | ||
|
|
||
| Dev package | ||
|
|
||
| ``` | ||
| nx serve rslib-module & nx storybook rslib-module | ||
| ``` | ||
|
|
||
| visit http://localhost:6006 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "name": "@examples/mf-react-component", | ||
| "private": true, | ||
| "exports": { | ||
| ".": { | ||
| "import": "./dist/esm/index.mjs", | ||
| "require": "./dist/cjs/index.js", | ||
| "types": "./dist/cjs/index.d.ts" | ||
| } | ||
| }, | ||
| "main": "./dist/cjs/index.js", | ||
| "module": "./dist/esm/index.mjs", | ||
| "types": "./dist/cjs/index.d.ts", | ||
| "scripts": { | ||
| "build": "rslib build", | ||
| "serve": "pnpm build && http-server -p 3000 ./dist/ --cors", | ||
| "storybook": "storybook dev -p 6006" | ||
| }, | ||
| "devDependencies": { | ||
| "storybook": "^8.3.6", | ||
| "storybook-react-rsbuild": "^0.1.1", | ||
| "@module-federation/enhanced": "workspace:*", | ||
| "@module-federation/rsbuild-plugin": "workspace:*", | ||
| "@module-federation/storybook-addon": "workspace:*", | ||
| "@rsbuild/plugin-react": "^1.0.5", | ||
| "@rslib/core": "^0.0.14", | ||
| "@types/react": "^18.3.11", | ||
| "http-server": "^14.1.1", | ||
| "react": "^18.3.1", | ||
| "react-dom": "^18.3.1" | ||
| }, | ||
| "peerDependencies": { | ||
| "react": "*" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "name": "rslib-module", | ||
| "$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
| "sourceRoot": "packages/rslib-module/src", | ||
| "projectType": "library", | ||
| "tags": ["type:app"], | ||
| "targets": { | ||
| "build": { | ||
| "executor": "nx:run-commands", | ||
| "options": { | ||
| "commands": ["npm run build --prefix apps/rslib-module"] | ||
| } | ||
| }, | ||
| "serve": { | ||
| "executor": "nx:run-commands", | ||
| "options": { | ||
| "commands": ["npm run serve --prefix apps/rslib-module"] | ||
| }, | ||
| "dependsOn": [ | ||
| { | ||
| "target": "build", | ||
| "dependencies": true | ||
| } | ||
| ] | ||
| }, | ||
| "storybook": { | ||
| "executor": "nx:run-commands", | ||
| "options": { | ||
| "commands": ["npm run storybook --prefix apps/rslib-module"] | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { pluginModuleFederation } from '@module-federation/rsbuild-plugin'; | ||
| import { pluginReact } from '@rsbuild/plugin-react'; | ||
| import { defineConfig } from '@rslib/core'; | ||
|
|
||
| const shared = { | ||
| dts: { | ||
| bundle: false, | ||
| }, | ||
| }; | ||
|
|
||
| export default defineConfig({ | ||
| lib: [ | ||
| { | ||
| ...shared, | ||
| format: 'esm', | ||
| output: { | ||
| distPath: { | ||
| root: './dist/esm', | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| ...shared, | ||
| format: 'cjs', | ||
| output: { | ||
| distPath: { | ||
| root: './dist/cjs', | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| ...shared, | ||
| format: 'mf', | ||
| output: { | ||
| distPath: { | ||
| root: './dist/mf', | ||
| }, | ||
| assetPrefix: 'http://localhost:3000/mf', | ||
| minify: true, | ||
| }, | ||
| plugins: [ | ||
| pluginModuleFederation({ | ||
| name: 'rslib_provider', | ||
| exposes: { | ||
| '.': './src/index.tsx', | ||
| }, | ||
| shared: { | ||
| react: { | ||
| singleton: true, | ||
| }, | ||
| 'react-dom': { | ||
| singleton: true, | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
| }, | ||
| ], | ||
| plugins: [pluginReact()], | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| interface CounterButtonProps { | ||
| onClick: () => void; | ||
| label: string; | ||
| [key: string]: any; | ||
| } | ||
|
|
||
| export const CounterButton: React.FC<CounterButtonProps> = ({ | ||
| onClick, | ||
| label, | ||
| ...props | ||
| }) => ( | ||
| <button type="button" onClick={onClick} {...props}> | ||
| {label} | ||
| </button> | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { CounterButton } from './CounterButton'; | ||
| import { useCounter } from './useCounter'; | ||
|
|
||
| export const Counter: React.FC = () => { | ||
| const { count, increment, decrement } = useCounter(); | ||
|
|
||
| return ( | ||
| <div> | ||
| <h2> | ||
| <span id="mf-e2e-lib-title">Counter From Rslib MF Format: </span> | ||
| <span id="mf-e2e-lib-content">{count}</span> | ||
| </h2> | ||
| <CounterButton id="mf-e2e-lib-decrease" onClick={decrement} label="-" /> | ||
| <CounterButton id="mf-e2e-lib-increase" onClick={increment} label="+" /> | ||
| </div> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import React from 'react'; | ||
| import { Counter } from 'rslib-module'; | ||
|
|
||
| const Component = () => <Counter />; | ||
|
|
||
| export default { | ||
| title: 'App Component', | ||
| component: Component, | ||
| }; | ||
|
|
||
| export const Primary = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { useState } from 'react'; | ||
|
|
||
| export const useCounter = (initialValue = 0) => { | ||
| const [count, setCount] = useState(initialValue); | ||
|
|
||
| const increment = () => setCount((prev) => prev + 1); | ||
| const decrement = () => setCount((prev) => prev - 1); | ||
|
|
||
| return { count, increment, decrement }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "jsx": "react-jsx", | ||
| "strict": true, | ||
| "skipLibCheck": true, | ||
| "esModuleInterop": true, | ||
| "paths": { | ||
| "*": ["./@mf-types/*"] | ||
| } | ||
| }, | ||
| "include": ["src/**/*", "src/stories"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.