Skip to content

Commit 462cb4c

Browse files
authored
docs: update storybook / upgrade-rslib (#373)
1 parent 103902b commit 462cb4c

File tree

11 files changed

+171
-53
lines changed

11 files changed

+171
-53
lines changed

website/docs/en/guide/_meta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
},
77
{
88
"type": "dir",
9-
"name": "framework",
10-
"label": "Framework"
9+
"name": "solution",
10+
"label": "Solution"
1111
},
1212
{
1313
"type": "dir",
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,95 @@
1+
import { PackageManagerTabs } from '@theme';
2+
13
# Use Storybook
4+
5+
[Storybook](https://storybook.js.org/) is a powerful tool for developing UI components in isolation for React, Vue, and other frameworks. It enables you to build and test components independently, which can accelerate both development and testing.
6+
7+
[storybook-rsbuild](https://github.com/rspack-contrib/storybook-rsbuild) is the Rsbuild powered Storybook builder, and provided the framework integration for React, Vue3 and vanilla JavaScript. The coherent Rsbuild system could make Storybook use an unified configuration with Rslib.
8+
9+
:::tip
10+
You can create a new project with Storybook by using [create-rslib](/guide/start/quick-start#creating-an-rslib-project).
11+
:::
12+
13+
## Getting Started
14+
15+
### Setup a Rslib project
16+
17+
This is the prerequisite for setting up Storybook. You need to have a Rslib project with components that you want to showcase in Storybook, check out [Solution](/guide/solution) to setup a Rslib project.
18+
19+
### Add Storybook to project
20+
21+
Set up a Storybook project with an existing Rslib project. To use React, Vue 3, vanilla JavaScript, or other frameworks, you must first install the appropriate Storybook framework package. For installation instructions, refer to the [Storybook Rsbuild documentation](https://storybook.rsbuild.dev/guide/framework.html).
22+
23+
Using React as an example, at this step you need to:
24+
25+
1. Install the dependencies for Storybook Rsbuild React framework. The essential ones include
26+
27+
- [storybook](https://www.npmjs.com/package/@storybook/addon-essentials): The Storybook core.
28+
- [@storybook/addon-essentials](https://www.npmjs.com/package/@storybook/addon-essentials): a curated collection of addons to bring out the best of Storybook.
29+
- [@rsbuild/core](https://www.npmjs.com/package/@rsbuild/core): Storybook builder.
30+
- [storybook-addon-rslib](https://www.npmjs.com/package/storybook-addon-rslib): This addon will make Storybook Rsbuild could derive Rsbuild configuration from Rslib config file.
31+
The addon will automatically read the Rslib configuration and apply it to Storybook Rsbuild, ensuring that the configuration is unified. You can check the [storybook-addon-rslib](https://storybook.rsbuild.dev/guide/integrations/rslib.html) documentation for available options.
32+
33+
<PackageManagerTabs
34+
command={{
35+
npm: 'npm add storybook @storybook/addon-essentials storybook-addon-rslib @rsbuild/core -D',
36+
yarn: 'yarn add storybook @storybook/addon-essentials storybook-addon-rslib @rsbuild/core -D',
37+
pnpm: 'pnpm add storybook @storybook/addon-essentials storybook-addon-rslib @rsbuild/core -D',
38+
bun: 'bun add storybook @storybook/addon-essentials storybook-addon-rslib @rsbuild/core -D',
39+
}}
40+
/>
41+
42+
The dependencies may vary for each framework, please refer to the [Storybook Rsbuild documentation](https://storybook.rsbuild.dev/guide/framework.html) for details. In this React example, we will install [storybook-rsbuild-react](https://www.npmjs.com/package/storybook-react-rsbuild) as the framework integration.
43+
44+
2. Configure the Storybook configuration file `.storybook/main.js`, specify the stories and addons, and set the framework with corresponding framework integration.
45+
46+
```js title=".storybook/main.js"
47+
export default {
48+
stories: [
49+
'../stories/**/*.mdx',
50+
'../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)',
51+
],
52+
addons: ['@storybook/addon-essentials', 'storybook-addon-rslib'],
53+
framework: 'storybook-react-rsbuild', // storybook-react-rsbuild for example
54+
};
55+
```
56+
57+
3. Add a simple story to the `stories` directory. For example, create a `Button.stories.js` file with the following content:
58+
59+
```js title="stories/Button.stories.js"
60+
import { Button } from '../src/Button';
61+
62+
const meta = {
63+
title: 'Example/Button',
64+
component: Button,
65+
};
66+
67+
export default meta;
68+
69+
export const Primary = {
70+
args: {
71+
primary: true,
72+
label: 'Button',
73+
},
74+
};
75+
```
76+
77+
:::tip
78+
In case you are using [Yarn Plug-n-Play](https://yarnpkg.com/features/pnp) or your project is set up within a mono repository environment, you might run into issues with module resolution. In such cases, you can add an `getAbsolutePath('storybook-addon-rslib')` function to resolve the addon. Check the [Storybook's FAQ](https://storybook.js.org/docs/faq#how-do-i-fix-module-resolution-in-special-environments) for more information.
79+
:::
80+
81+
There you go, you could start and build the Storybook server with the following command:
82+
83+
```bash
84+
npx storybook dev // development mode
85+
npx storybook build // build static files
86+
```
87+
88+
Check out more details in the [Storybook Rsbuild documentation](https://storybook.rsbuild.dev/) and the [Storybook documentation](https://storybook.js.org/docs/react/get-started/introduction).
89+
90+
{/* TODO: */}
91+
{/* ## Module Federation */}
92+
93+
## Example
94+
95+
- [React component library + Rslib + Storybook](https://github.com/rspack-contrib/storybook-rsbuild/tree/main/sandboxes/rslib-react-component)

website/docs/en/guide/basic/_meta.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
"typescript",
55
"output-format",
66
"output-structure",
7-
"upgrade-rslib",
8-
"umd"
7+
"upgrade-rslib"
98
]

website/docs/en/guide/basic/umd.mdx

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,68 @@
11
# Upgrade Rslib
2+
3+
This section explains how to upgrade the project's Rslib dependencies to the latest version.
4+
5+
{/* TODO */}
6+
{/* > Please see [Releases](/community/releases/index) to understand the Rsbuild release strategy. */}
7+
8+
:::info
9+
Rslib is still in the early stages of development, and the API may change frequently. We recommend upgrading to the latest version to access new features and bug fixes. We plan to release version 0.1.0 in the fourth quarter of 2024.
10+
:::
11+
12+
## Using Taze
13+
14+
We recommend using [Taze](https://github.com/antfu-collective/taze) to upgrade the Rslib version. Taze is a CLI tool for updating npm dependencies.
15+
16+
### Usage
17+
18+
Run the following command to upgrade all dependencies that include `rslib` and `rsbuild` in their names:
19+
20+
```bash
21+
npx taze major --include "/(rsbuild|rslib)/" -w
22+
```
23+
24+
:::tip
25+
Rslib has not yet reached version 0.1.0, so you need to add the `major` parameter when updating.
26+
:::
27+
28+
The result will look similar to:
29+
30+
```bash
31+
rslib - 2 major, 1 patch
32+
33+
@rsbuild/plugin-react dev ~2mo ^1.0.1 → ^1.0.6
34+
@rslib/core dev ~7d ^0.0.15 → ^0.0.16
35+
rsbuild-plugin-dts dev ~7d ^0.0.15 → ^0.0.16
36+
37+
ℹ changes written to package.json, run npm i to install updates.
38+
```
39+
40+
You can also adjust the `include` pattern to match specific packages, for example, to upgrade only packages under the `@rslib` scope:
41+
42+
```bash
43+
npx taze --include /@rslib/ -w
44+
```
45+
46+
### Options
47+
48+
Here are some examples of using taze options.
49+
50+
- In a monorepo, you can add the `-r` option to upgrade recursively:
51+
52+
```bash
53+
npx taze --include /(rsbuild|rslib)/ -w -r
54+
```
55+
56+
- Add `-l` to upgrade locked versions:
57+
58+
```bash
59+
npx taze --include /(rsbuild|rslib)/ -w -l
60+
```
61+
62+
- To upgrade to a major version:
63+
64+
```bash
65+
npx taze major --include /(rsbuild|rslib)/ -w
66+
```
67+
68+
> For more options, please refer to the [taze documentation](https://github.com/antfu-collective/taze).

website/docs/en/guide/solution.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Solution
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)