Skip to content

Commit

Permalink
docs: polish Rslib (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Nov 6, 2024
1 parent c8804dc commit 3f8eee9
Show file tree
Hide file tree
Showing 31 changed files with 574 additions and 223 deletions.
File renamed without changes.
5 changes: 2 additions & 3 deletions packages/addon-rslib/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import type {
RsbuildFinal,
StorybookConfigRsbuild,
} from 'storybook-builder-rsbuild'

import { startMFDevServer } from './init'

import { startMFDevServer } from './mf'
import type { AddonOptions } from './types'

type BaseOptions = Parameters<RsbuildFinal>[1]
Expand All @@ -21,6 +19,7 @@ export const rsbuildFinal: StorybookConfigRsbuild['rsbuildFinal'] = async (
cwd: cwd,
path: configPath,
})

await startMFDevServer(rslibConfig)

const libConfig = libIndex === false ? {} : rslibConfig.lib[libIndex]
Expand Down
80 changes: 71 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sandboxes/react-16/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# React v18 (Rsbuild | TypeScript)</h1>
# React v18 (Rsbuild | TypeScript)

Run Storybook

Expand Down
2 changes: 1 addition & 1 deletion sandboxes/react-18/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# React v18 (Rsbuild | TypeScript)</h1>
# React v18 (Rsbuild | TypeScript)

Run Storybook

Expand Down
2 changes: 1 addition & 1 deletion sandboxes/react-testing/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# React v18 (Rsbuild | TypeScript)</h1>
# React v18 (Rsbuild | TypeScript)

Run Storybook and Coverage

Expand Down
9 changes: 0 additions & 9 deletions sandboxes/rslib-react-component/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ const config: StorybookConfig = {
},
},
},
{
name: '@module-federation/storybook-addon/preset',
options: {
remotes: {
'rslib-module':
'rslib-module@http://localhost:3001/mf/mf-manifest.json',
},
},
},
],
framework: {
name: getAbsolutePath('storybook-react-rsbuild'),
Expand Down
2 changes: 1 addition & 1 deletion sandboxes/rslib-react-component/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# React v18 + Rslib (Rsbuild | Rslib | TypeScript)</h1>
# React v18 + Rslib

Run Storybook

Expand Down
2 changes: 0 additions & 2 deletions sandboxes/rslib-react-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"react-dom": "18.3.1"
},
"devDependencies": {
"@module-federation/rsbuild-plugin": "^0.6.14",
"@module-federation/storybook-addon": "0.0.0-next-20241106024856",
"@rsbuild/core": "1.0.19",
"@chromatic-com/storybook": "^3.2.2",
"@rsbuild/plugin-react": "1.0.5",
Expand Down
33 changes: 0 additions & 33 deletions sandboxes/rslib-react-component/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin'
import { pluginReact } from '@rsbuild/plugin-react'
import { pluginSass } from '@rsbuild/plugin-sass'
import { type LibConfig, defineConfig } from '@rslib/core'
Expand Down Expand Up @@ -40,38 +39,6 @@ export default defineConfig({
},
},
},
{
format: 'mf',
output: {
distPath: {
root: './dist/mf',
},
assetPrefix: 'http://localhost:3001/mf',
},
dev: {
assetPrefix: 'http://localhost:3001/mf',
},
// just for dev
server: {
port: 3001,
},
plugins: [
pluginModuleFederation({
name: 'rslib_provider',
exposes: {
'.': './src/index.tsx',
},
shared: {
react: {
singleton: true,
},
'react-dom': {
singleton: true,
},
},
}),
],
},
],
plugins: [
pluginReact({
Expand Down
34 changes: 17 additions & 17 deletions sandboxes/rslib-react-component/stories/CounterButton.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ export const Primary: Story = {
},
}

// export const Secondary: Story = {
// args: {
// label: 'CounterButton',
// },
// }
export const Secondary: Story = {
args: {
label: 'CounterButton',
},
}

// export const Large: Story = {
// args: {
// size: 'large',
// label: 'CounterButton',
// },
// }
export const Large: Story = {
args: {
size: 'large',
label: 'CounterButton',
},
}

// export const Small: Story = {
// args: {
// size: 'small',
// label: 'CounterButton',
// },
// }
export const Small: Story = {
args: {
size: 'small',
label: 'CounterButton',
},
}
5 changes: 2 additions & 3 deletions sandboxes/rslib-react-component/stories/mfCounter.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @ts-ignore skip type check in ci because we set @mf-types into .gitignore
import { Counter } from 'rslib-module'
import { Counter } from '../src/components/Counter'

export default {
title: 'Example/MFCounter',
title: 'Example/Counter',
component: Counter,
}

Expand Down
5 changes: 1 addition & 4 deletions sandboxes/rslib-react-component/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"strict": true,
"resolveJsonModule": true,
"jsx": "react",
"outDir": "dist",
"paths": {
"*": ["./@mf-types/*"]
}
"outDir": "dist"
},
"include": ["src/**/*", ".storybook/**/*", "stories/**/*"]
}
54 changes: 54 additions & 0 deletions sandboxes/rslib-react-mf/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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)',
],
addons: [
'@storybook/addon-onboarding',
'@storybook/addon-links',
'@storybook/addon-essentials',
'@chromatic-com/storybook',
'@storybook/addon-interactions',
{
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',
},
},
},
],
framework: {
name: getAbsolutePath('storybook-react-rsbuild'),
options: {},
},
docs: {
autodocs: 'tag',
},
typescript: {
reactDocgen: 'react-docgen-typescript',
check: true,
},
}

export default config
14 changes: 14 additions & 0 deletions sandboxes/rslib-react-mf/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Preview } from '@storybook/react'

const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
}

export default preview
15 changes: 15 additions & 0 deletions sandboxes/rslib-react-mf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# React v18 + Rslib + Module Federation

Run Storybook

pnpm storybook

```bash

```

Build Storybook

```bash
pnpm build-storybook
```
Loading

0 comments on commit 3f8eee9

Please sign in to comment.