-
-
Notifications
You must be signed in to change notification settings - Fork 57
feat: support use storybook to dev rslib module federation format assets and also support hmr #349
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 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
017f0fb
feat: support use storybook to dev rslib module federation format
63b271e
chore: modify comment
147a4cf
chore: change comment
3c78423
chore: update lock file
44729e6
chore: sync main branch
56cde56
chore: use nx command to replace pnpm
92ca3e3
test: fix type check error in ci
f9d1041
chore: re export composeCreateRsbuildConfig in rslib core
c3cc8a1
chore: remove useless code
nyqykk ddca4df
chore: sync main branch
nyqykk bb574ca
docs: add docs for storybook
nyqykk 5f08e93
chore: solve conversation issues
nyqykk c81a6a4
docs: cls
nyqykk e7d753d
docs: change express
nyqykk cbd78df
docs: solve docs error
nyqykk 783ea07
correct lockfile
fi3ework 33069e3
chore: update
Timeless0911 ed48cf4
Merge branch 'main' into feat/dev-mf-assets
nyqykk 08ddd5f
feat: support dev command to dev mf format
nyqykk 9716aa6
chore: sync code
nyqykk b07ceed
docs: add dev command into doc
nyqykk ac60d7a
docs: add command into cli
nyqykk 98169eb
docs: stress somewhere
nyqykk 156ca80
Merge branch 'main' into feat/dev-mf-assets
nyqykk 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| registry = 'https://registry.npmjs.org/' | ||
| strict-peer-dependencies=false | ||
| auto-install-peers=false | ||
| hoist-patterns[]=[] |
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "name": "@example/mf-host", | ||
| "name": "@examples/mf-host", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "scripts": { | ||
|
|
||
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
42 changes: 42 additions & 0 deletions
42
examples/module-federation/mf-react-component/.storybook/main.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,42 @@ | ||
| 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: [ | ||
| '../stories/**/*.mdx', | ||
| '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)', | ||
| ], | ||
| framework: { | ||
| name: getAbsolutePath('storybook-react-rsbuild'), | ||
| options: {}, | ||
| }, | ||
| addons: [ | ||
| { | ||
| name: getAbsolutePath('storybook-addon-rslib'), | ||
| options: { | ||
| rslib: { | ||
| include: ['**/stories/**'], | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: '@module-federation/storybook-addon/preset', | ||
| options: { | ||
| remotes: { | ||
| 'rslib-module': | ||
| 'rslib-module@http://localhost:3001/mf/mf-manifest.json', | ||
| }, | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| 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 |
|---|---|---|
| @@ -1,3 +1,37 @@ | ||
| # @examples/mf-react-component | ||
|
|
||
| This example demonstrates how to use Rslib to build a simple Module Federation React component. | ||
|
|
||
| ### Usage | ||
|
|
||
| Dev MF module | ||
|
|
||
| 1. Start remote module which is loaded by Rslib module. | ||
|
|
||
| ``` | ||
| nx run @examples/mf-remote:dev | ||
| ``` | ||
|
|
||
| 2. Start MF dev mode. | ||
|
|
||
| ``` | ||
| nx run @examples/mf-react-component:dev | ||
| ``` | ||
|
|
||
| 3. Use Storybook to development component. | ||
|
|
||
| ``` | ||
| nx run @examples/mf-react-component:storybook | ||
| ``` | ||
|
|
||
| Build | ||
|
|
||
| ``` | ||
| nx run @examples/mf-react-component:build | ||
| ``` | ||
|
|
||
| Build and Serve dist | ||
|
|
||
| ``` | ||
| nx run @examples/mf-react-component:serve | ||
| ``` |
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
12 changes: 12 additions & 0 deletions
12
examples/module-federation/mf-react-component/stories/index.stories.tsx
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 @@ | ||
| import React from 'react'; | ||
| // @ts-ignore ignore remote module type check for passing ci run build because we set @mf-types folder in .gitignore | ||
nyqykk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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
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 |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| { | ||
| "name": "@example/mf", | ||
| "name": "@examples/mf", | ||
| "private": true, | ||
| "scripts": { | ||
| "dev:all": "pnpm dev:host & pnpm dev:lib & pnpm dev:remote", | ||
| "dev:all": "pnpm dev:host & pnpm serve:lib & pnpm dev:remote", | ||
| "dev:host": "pnpm --filter mf-host dev", | ||
| "dev:lib": "pnpm --filter mf-react-component run serve", | ||
| "dev:remote": "pnpm --filter mf-remote dev" | ||
| "dev:remote": "pnpm --filter mf-remote dev", | ||
| "serve:lib": "pnpm --filter mf-react-component run serve" | ||
| } | ||
| } |
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,49 @@ | ||
| import { createRsbuild, mergeRsbuildConfig } from '@rsbuild/core'; | ||
| import { composeCreateRsbuildConfig } from './config'; | ||
|
|
||
| import type { RsbuildConfig, RsbuildInstance } from '@rsbuild/core'; | ||
| import type { RslibConfig } from './types'; | ||
|
|
||
| export async function startMFDevServer( | ||
nyqykk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| config: RslibConfig, | ||
| ): Promise<RsbuildInstance | undefined> { | ||
| const rsbuildInstance = await initMFRsbuild(config); | ||
| return rsbuildInstance; | ||
| } | ||
|
|
||
| async function initMFRsbuild( | ||
| rslibConfig: RslibConfig, | ||
| ): Promise<RsbuildInstance | undefined> { | ||
| const rsbuildConfigObject = await composeCreateRsbuildConfig(rslibConfig); | ||
| const mfRsbuildConfig = rsbuildConfigObject.find( | ||
| (config) => config.format === 'mf', | ||
| ); | ||
|
|
||
| if (!mfRsbuildConfig) { | ||
| // no mf format, return. | ||
| return; | ||
| } | ||
|
|
||
| mfRsbuildConfig.config = changeEnvToDev(mfRsbuildConfig.config); | ||
| const rsbuildInstance = await createRsbuild({ | ||
| rsbuildConfig: mfRsbuildConfig.config, | ||
| }); | ||
| await rsbuildInstance.startDevServer(); | ||
| return rsbuildInstance; | ||
| } | ||
|
|
||
| function changeEnvToDev(rsbuildConfig: RsbuildConfig) { | ||
| return mergeRsbuildConfig(rsbuildConfig, { | ||
| mode: 'development', | ||
| dev: { | ||
| writeToDisk: true, | ||
| }, | ||
| tools: { | ||
| rspack: { | ||
| optimization: { | ||
| nodeEnv: 'development', | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
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.