@modern-js/main-doc 2.67.9 → 2.67.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,231 +2,47 @@
2
2
  sidebar_position: 15
3
3
  ---
4
4
 
5
- # Using Storybook
6
-
7
- [Storybook](https://storybook.js.org/) is a tool dedicated to component debugging, providing around component development.
8
-
9
- - Develop UIs that are more durable
10
- - Test UIs with less effort and no flakes
11
- - Document UI for your team to reuse
12
- - Share how the UI actually works
13
- - Automate UI workflows
14
-
15
- :::tip
16
- This tutorial is suitable for Storybook V7 users. If you are using an old version of Storybook V6 (using the @modern-js/plugin-storybook plugin), you can refer to the [Migration Guide](#migration-guide) to upgrade.
17
- :::
18
-
19
- ## Quick Start
20
-
21
- Modern.js integrates Storybook debugging capabilities by default. You can directly enable the Storybook feature by using the following command:
22
-
23
- ```bash
24
- $ npx modern new
25
- ? Please select the operation you want: Enable features
26
- ? Please select the feature name: Enable「Storybook」V7
27
- ```
28
-
29
- This command will create a template for Storybook, including:
30
-
31
- - Creating a configuration folder .storybook and a default configuration file .storybook/main.ts.
32
- - Creating example story components.
33
- - Updating package.json to add dependencies @storybook/addon-essentials and @modern-js/storybook, as well as creating Storybook-related scripts.
34
-
35
- To start, run `npm run storybook`.
36
-
37
- ## Enable Rspack build
38
-
39
- Rspack is known for its fast build speed. To use Rspack as a build tool in Modern.js, you only need to configure it as follows:
40
-
41
- ```diff filename='.storybook/main.js'
42
- const config = {
43
- framework: {
44
- name: '@modern-js/storybook',
45
- options: {
46
- - bundler: 'webpack'
47
- + bundler: 'rspack'
48
- },
49
- },
50
- typescript: {
51
- - reactDocgen: 'react-docgen-typescript'
52
- + reactDocgen: 'react-docgen'
53
- }
54
- };
55
-
56
- export default config;
57
- ```
58
-
59
- Note that in the above configuration, the reactDocgen configuration has been changed because Rspack currently does not support @storybook/react-docgen-typescript-plugin.
60
-
61
- ## Configurations
62
-
63
- There are some configurations in `.storybook/main.js`.
64
-
65
- ### configPath
66
-
67
- - **Type**: `string`
68
- - **Default**: `modern.config.(j|t)s`
69
-
70
- Specify the path of Modern.js configuration.
71
-
72
- Example:
73
-
74
- ```javascript filename='.storybook/main.js'
75
- const config = {
76
- framework: {
77
- name: '@modern-js/storybook',
78
- options: {
79
- configPath: 'modern.storybook.config.ts',
80
- },
81
- },
82
- };
83
-
84
- export default config;
85
- ```
86
-
87
- ### bundler
88
-
89
- - **Type**: `'webpack' | 'rspack'`
90
- - **Default**: `webpack`
91
-
92
- Specify the underlying build tool to use either Webpack or Rspack.
93
-
94
- Example:
95
-
96
- ```javascript filename='.storybook/main.js'
97
- const config = {
98
- framework: {
99
- name: '@modern-js/storybook',
100
- options: {
101
- bundler: 'rspack',
102
- },
103
- },
104
- };
105
-
106
- export default config;
107
- ```
108
-
109
- ### builderConfig
5
+ import { PackageManagerTabs } from '@theme'
110
6
 
111
- - **Type**: `BuilderConfig`
112
- - **Default**: `undefined`
113
-
114
- To modify the configuration of build, which has a higher priority than the configuration file, you can specify the build configuration directly here if you do not want to use the configuration file.
115
-
116
- Example:
117
-
118
- ```javascript filename='.storybook/main.js'
119
- const config = {
120
- framework: {
121
- name: '@modern-js/storybook',
122
- options: {
123
- builderConfig: {
124
- alias: {
125
- react: require.resolve('react'),
126
- 'react-dom': require.resolve('react-dom'),
127
- },
128
- },
129
- },
130
- },
131
- };
132
-
133
- export default config;
134
- ```
135
-
136
- ## Command Line Interface
137
-
138
- @modern-js/storybook proxies some of the storybook cli commands.
139
-
140
- ### storybook dev
141
-
142
- Start Storybook, more details at [storybook#dev](https://storybook.js.org/docs/react/api/cli-options#dev).
143
-
144
- ### storybook build
145
-
146
- Build Storybook for production, more details at [storybook#build](https://storybook.js.org/docs/react/api/cli-options#build).
147
-
148
- ## Storybook addon compatibility
149
-
150
- Due to the current version of Storybook in the document being version 7, please select the addon for Storybook V7.
151
-
152
- When an addon does not require additional Babel or Webpack configurations, it can be used directly, such as @storybook/addon-essentials.
153
-
154
- For some addons that require dependencies on Babel plugins and Webpack configurations, such as @storybook/addon-coverage, only @modern-js/builder-webpack-provider supports them.
155
-
156
- ## Benefits
157
-
158
- Using @modern-js/storybook can bring you lightning-fast builds with Rspack, without the need for tedious configuration. It comes with many best practices for web development out-of-the-box, such as code splitting strategies, built-in support for CSS modules and postcss, TypeScript support, and commonly used Babel plugins.
159
-
160
- The powerful build capabilities of Modern.js can be directly used in Storybook projects.
161
-
162
- ## Trouble Shooting
163
-
164
- 1. Modern.js won't load your other configurations like `babel.config.json`, babel config needs to be set in Modern.js config, [tools.babel](/configure/app/tools/babel).
165
- Webpack configuration can be written in either [tools.webpack](/configure/app/tools/webpack) or [tools.webpackChain](/configure/app/tools/webpack-chain).
166
-
167
- 2. If you find that the build performance is not good, please check if the Storybook automatic documentation generation feature is enabled. For optimal performance, configure it to use `react-docgen`. The difference between `react-docgen` and `react-docgen-typescript` is that the former is implemented based on Babel, while the latter is implemented based on TypeScript. The former has better performance but weaker type inference capabilities. If you are using Rspack for the build, only `react-docgen` is supported.
168
-
169
- ```javascript filename='.storybook/main.js'
170
- const config = {
171
- typescript: {
172
- reactDocgen: 'react-docgen',
173
- },
174
- };
175
-
176
- export default config;
177
- ```
178
-
179
- ## Migration Guide
180
-
181
- ### Migrate from @modern-js/plugin-storybook
182
-
183
- If you are a user migrating from V6 to V7, you can use V7 through [the above method](#quick-start) and make the following adjustments:
184
-
185
- ##### Modify configuration file
186
-
187
- If you have made some custom configurations to Storybook in the older version, you need to move the configuration file `root/config/storybook/main.(j|t)s` to `root/.storybook/main.(j|t)s`.
188
-
189
- And then add the following lines in `root/.storybook/main.(j|t)s`, specify framework as `@modern-js/storybook`.
7
+ # Using Storybook
190
8
 
191
- ```diff
192
- const config = {
193
- + framework: {
194
- + name: '@modern-js/storybook'
195
- + }
196
- };
9
+ [Storybook](https://storybook.js.org/) is a tool specifically designed for component debugging. It provides:
197
10
 
198
- export default config;
199
- ```
11
+ - A rich variety of debugging capabilities
12
+ - Integration with some testing tools
13
+ - Reusable documentation content
14
+ - Sharing capabilities
15
+ - Workflow automation
200
16
 
201
- ##### Update Dependencies
17
+ ## Principle
202
18
 
203
- Update dependencies like @storybook/addon-\* to major version 7.
19
+ Rsbuild provides [Storybook Rsbuild](https://storybook.rsbuild.rs/index.html), which allows any Rsbuild project to use this tool for building Storybook.
204
20
 
205
- ##### Remove @modern-js/plugin-storybook
21
+ Modern.js implements `storybook-addon-modernjs` based on this tool. This plugin loads the Modern.js configuration file and converts it into a configuration usable by **Storybook Rsbuild**.
206
22
 
207
- 在 modern.config.(j|t)s 中删除 @modern-js/plugin-storybook 插件的注册。
23
+ :::info
24
+ This document only provides the simplest usage. For more information, please refer to [Storybook Rsbuild Modern.js Integration](https://storybook.rsbuild.rs/guide/integrations/modernjs.html).
25
+ :::
208
26
 
209
- ##### Modify Storybook Syntax
27
+ ## Installation
210
28
 
211
- Follow the official Storybook documentation to make the necessary updates for some breaking changes, such as changes in story writing and MDX syntax. You can refer to the migration guide at [storybook migrate doc](https://storybook.js.org/docs/react/migration-guide).
29
+ <PackageManagerTabs command="install @rsbuild/core storybook-builder-rsbuild storybook-addon-modernjs -D" />
212
30
 
213
- ### Native Storybook users
31
+ You need to install `@rsbuild/core` in your project, otherwise the plugin may not work properly.
214
32
 
215
- Modern.js only support Storybook 7, so you need to upgrade from Storybook version 6 to version 7, please follow the steps outlined in the official Storybook documentation at [storybook migrate doc](https://storybook.js.org/docs/react/migration-guide).
33
+ ## Configure `.storybook/main.ts`
216
34
 
217
- ```diff filename='.storybook/main.js'
218
- const config = {
219
- - framework: '@storybook/react-webapck5',
220
- + framework: {
221
- + name: '@modern-js/storybook'
222
- + },
223
- };
35
+ ```ts
36
+ import type { StorybookConfig } from 'storybook-react-rsbuild'
224
37
 
225
- export default config;
38
+ const config: StorybookConfig = {
39
+ stories: ['../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
40
+ addons: ['storybook-addon-modernjs'],
41
+ framework: ['storybook-react-rsbuild'],
42
+ }
43
+ export default config
226
44
  ```
227
45
 
228
- The default config file path is `modern.config.(j|t)s`, for the detail config, see [modern.js config](/configure/app/usage).
229
-
230
- If the original project includes configurations for Babel, they need to be written in the modern configuration. Most Babel configurations have already been included in Modern.js.
46
+ ## Example
231
47
 
232
- After installation, make the corresponding [configuration](/guides/basic-features/debug/using-storybook#configurations).
48
+ You can check out the [example](https://github.com/rspack-contrib/storybook-rsbuild/tree/main/sandboxes/modernjs-react) to learn how to use Storybook in Modern.js.
@@ -2,6 +2,8 @@
2
2
  sidebar_position: 15
3
3
  ---
4
4
 
5
+ import { PackageManagerTabs } from '@theme'
6
+
5
7
  # 使用 Storybook
6
8
 
7
9
  [Storybook](https://storybook.js.org/) 是一个专门用于组件调试的工具,它围绕着组件开发提供了:
@@ -12,221 +14,35 @@ sidebar_position: 15
12
14
  - 可分享能力
13
15
  - 工作流程自动化
14
16
 
15
- :::tip
16
- 本教程适用于新版 Storybook V7 用户,如果你在使用老版本 Storybook V6 (有使用 @modern-js/plugin-storybook 插件),可参考 [迁移指南](#迁移指南) 进行升级。
17
- :::
18
-
19
- ## 快速开始
20
-
21
- Modern.js 默认集成了 Storybook 的调试能力,当我们想要对组件进行调试的时候,可以通过以下方式启用 Storybook 调试功能:
22
-
23
- ```bash
24
- $ npx modern new
25
- ? 请选择你想要的操作 启用可选功能
26
- ? 请选择功能名称 启用「Storybook」V7
27
- ```
28
-
29
- 该命令会创建好 Storybook 常用的模版,包括:
30
-
31
- - 创建配置文件夹 `.storybook`,以及默认配置文件 `.storybook/main.ts`
32
- - 创建 stories 组件示例
33
- - 更新 package.json,新增依赖 @storybook/addon-essential 和 @modern-js/storybook,以及创建 storybook 相关脚本
34
-
35
- 运行 `npm run storybook` 即可启动 Storybook 预览。
36
-
37
- ## 开启 Rspack 构建
38
-
39
- Rspack 构建速度非常快,在 Modern.js 中只需要如下配置即可使用 Rspack 作为构建工具。
40
-
41
- ```diff filename='.storybook/main.js'
42
- const config = {
43
- framework: {
44
- name: '@modern-js/storybook',
45
- options: {
46
- - bundler: 'webpack'
47
- + bundler: 'rspack'
48
- },
49
- },
50
- typescript: {
51
- - reactDocgen: 'react-docgen-typescript'
52
- + reactDocgen: 'react-docgen'
53
- }
54
- };
55
-
56
- export default config;
57
- ```
58
-
59
- 注意上面配置中,更改了 reactDocgen 配置,因为 Rspack 目前还不支持 @storybook/react-docgen-typescript-plugin。
60
-
61
- ## 配置
62
-
63
- 在 `.storybook/main.js` 中包含一些配置。
64
-
65
- ### configPath
17
+ ## 原理
66
18
 
67
- - **类型**: `string`
68
- - **默认值**: `modern.config.(j|t)s`
19
+ Rsbuild 提供了 [Storybook Rsbuild](https://storybook.rsbuild.rs/index.html),任何 Rsbuild 的项目都可以使用该工具来实现 Storybook 的构建。
69
20
 
70
- 用于指定配置文件路径。
21
+ Modern.js 基于此工具实现了 `storybook-addon-modernjs`,该插件会加载 Modern.js 配置文件,并转换为 **Storybook Rsbuild** 可用的配置。
71
22
 
72
- 例如
73
-
74
- ```javascript filename='.storybook/main.js'
75
- const config = {
76
- framework: {
77
- name: '@modern-js/storybook',
78
- options: {
79
- configPath: 'modern.storybook.config.ts',
80
- },
81
- },
82
- };
83
-
84
- export default config;
85
- ```
86
-
87
- ### bundler
88
-
89
- - **类型**: `'webpack' | 'rspack'`
90
- - **默认值**: `webpack`
91
-
92
- 指定底层构建工具使用 Webpack 还是 Rspack。
93
-
94
- 例如
95
-
96
- ```javascript filename='.storybook/main.js'
97
- const config = {
98
- framework: {
99
- name: '@modern-js/storybook',
100
- options: {
101
- bundler: 'rspack',
102
- },
103
- },
104
- };
105
-
106
- export default config;
107
- ```
108
-
109
- ### builderConfig
110
-
111
- - **类型**: `BuilderConfig`
112
- - **默认值**: `undefined`
113
-
114
- 更改构建配置,该配置比配置文件拥有更高的优先级,若不想使用配置文件,也可直接在此处指定。
115
-
116
- 例如
117
-
118
- ```javascript filename='.storybook/main.js'
119
- const config = {
120
- framework: {
121
- name: '@modern-js/storybook',
122
- options: {
123
- builderConfig: {
124
- alias: {
125
- react: require.resolve('react'),
126
- 'react-dom': require.resolve('react-dom'),
127
- },
128
- },
129
- },
130
- },
131
- };
132
-
133
- export default config;
134
- ```
135
-
136
- ## 命令行
137
-
138
- @modern-js/storybook 代理了部分 storybook cli 的命令。
139
-
140
- ### storybook dev
141
-
142
- 启动 Storybook,详情请看 [storybook#dev](https://storybook.js.org/docs/react/api/cli-options#dev)
143
-
144
- ### storybook build
145
-
146
- 对 Storybook 进行生产环境构建,详情请看 [storybook#build](https://storybook.js.org/docs/react/api/cli-options#build)
147
-
148
- ## Storybook addon 兼容性
149
-
150
- 由于当前文档中的 Storybook 版本为 7,因此请选择 storybook V7 的 addon。
151
-
152
- 当 addon 不需要额外的 Babel 或 Webpack 配置时,可以直接使用,如 @storybook/addon-essentials。
153
-
154
- 部分 addon 需要依赖 babel 插件和 Webpack 配置时,如 @storybook/addon-coverage,只有使用 webpack 构建才会支持。
155
-
156
- ## 收益
157
-
158
- 使用 @modern-js/storybook 可以带给你 Rspack 超快的构建,并且完全无需繁琐配置,开箱即用。并且默认包含了许多 Web 构建中的最佳实践,例如 code splitting 策略,内置 css module 和 postcss,开箱即用的 TypeScript 支持,内置常用 Babel 插件等等。
159
-
160
- Modern.js 的构建能力和配置都可以直接在 Storybook 项目中使用。
161
-
162
- ## Trouble Shooting
163
-
164
- 1. 使用 Modern.js 启动 storybook 时不会读取 babel.config.json 等配置文件,因此 babel 配置需要在 [tools.babel](/configure/app/tools/babel) 中进行配置。
165
- 同样的 webpack 配置需要写在 [tools.webpack](/configure/app/tools/webpack) 或 [tools.webpackChain](/configure/app/tools/webpack-chain) 中。
166
-
167
- 2. 如果发现构建速度很慢,请检查是否开启了自动文档生成功能,如果想要最高的性能,请配置为 `react-docgen`。`react-docgen` 和 `react-docgen-typescript` 的区别是,前者基于 Babel 实现,后者基于 TypeScript 实现,前者性能会更好,但类型推断能力更弱。如果使用 Rspack 构建,则只支持 `react-docgen`。
168
-
169
- ```javascript filename='.storybook/main.js'
170
- const config = {
171
- typescript: {
172
- reactDocgen: 'react-docgen',
173
- },
174
- };
175
-
176
- export default config;
177
- ```
178
-
179
- ## 迁移指南
180
-
181
- ### 从 Modern.js Storybook V6 迁移
182
-
183
- 如果你是从 V6 迁移至 V7 的用户,可以通过 [上述方式](#快速开始) 使用 V7,同时做以下调整:
184
-
185
- ##### 修改配置文件
186
-
187
- 若你在旧版本对 storybook 进行了一些自定义配置,需要将配置文件 `root/config/storybook/main.(j|t)s` 移动到 `root/.storybook/main.(j|t)s`。
188
-
189
- 并在 `root/.storybook/main.(j|t)s` 中添加以下配置,指定 framework 为 @modern-js/storybook:
190
-
191
- ```diff
192
- const config = {
193
- + framework: {
194
- + name: '@modern-js/storybook'
195
- + },
196
- };
197
-
198
- export default config;
199
- ```
200
-
201
- ##### 依赖升级
202
-
203
- 升级 @storybook/addon-\* 系列依赖,升级到 7 版本。
204
-
205
- ##### 移除 @modern-js/plugin-storybook 插件
206
-
207
- 在 modern.config.(j|t)s 中删除 @modern-js/plugin-storybook 插件的注册。
23
+ :::info
24
+ 本文档仅提供最简单的使用方式,更多内容可参考 [Storybook Rsbuild Modern.js 集成](https://storybook.rsbuild.rs/guide/integrations/modernjs.html)。
25
+ :::
208
26
 
209
- ##### 修改 Storybook 写法
27
+ ## 安装
210
28
 
211
- 按照 Storybook 官网文档,对一些 breaking change 做相应的更新,例如 stories 的写法,MDX 的写法等,参考[storybook 迁移文档](https://storybook.js.org/docs/react/migration-guide)。
29
+ <PackageManagerTabs command="install @rsbuild/core storybook-builder-rsbuild storybook-addon-modernjs -D" />
212
30
 
213
- ### 从原生 Storybook 项目迁移
31
+ 你需要在项目中安装 `@rsbuild/core`,否则该插件可能无法正常工作。
214
32
 
215
- 若当前 Storybook 版本还是 6,需要先按照 Storybook 官网文档升级到版本 7,参考 [storybook 迁移文档](https://storybook.js.org/docs/react/migration-guide)。
33
+ ## 配置 `.storybook/main.ts`
216
34
 
217
- ```diff filename='.storybook/main.js'
218
- const config = {
219
- - framework: '@storybook/react-webapck5',
220
- + framework: {
221
- + name: '@modern-js/storybook'
222
- + },
223
- };
35
+ ```ts
36
+ import type { StorybookConfig } from 'storybook-react-rsbuild'
224
37
 
225
- export default config;
38
+ const config: StorybookConfig = {
39
+ stories: ['../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
40
+ addons: ['storybook-addon-modernjs'],
41
+ framework: ['storybook-react-rsbuild'],
42
+ }
43
+ export default config
226
44
  ```
227
45
 
228
- Modern.js 的配置文件默认为 `modern.config.(j|t)s`,配置请查看 [modern.js 配置](/configure/app/usage)。
229
-
230
- 若原来项目中包含了 Babel 等配置,需要对应的写在 modern 配置中,大部分 Babel 配置已经包含进了 Modern.js。
46
+ ## 示例
231
47
 
232
- 安装完成后进行相应的[配置](/guides/basic-features/debug/using-storybook#配置)
48
+ 你可以查看 [示例](https://github.com/rspack-contrib/storybook-rsbuild/tree/main/sandboxes/modernjs-react) 了解 Modern.js 中使用 Storybook 的方式。
package/package.json CHANGED
@@ -15,28 +15,28 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.67.9",
18
+ "version": "2.67.11",
19
19
  "publishConfig": {
20
20
  "registry": "https://registry.npmjs.org/",
21
21
  "access": "public"
22
22
  },
23
23
  "dependencies": {
24
24
  "mermaid": "^11.4.1",
25
- "@modern-js/sandpack-react": "2.67.9"
25
+ "@modern-js/sandpack-react": "2.67.11"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@rsbuild/plugin-sass": "1.3.2",
29
29
  "@shikijs/transformers": "^3.4.2",
30
- "@rspress/shared": "2.0.0-beta.11",
31
- "@rspress/plugin-llms": "2.0.0-beta.11",
30
+ "@rspress/shared": "2.0.0-beta.16",
31
+ "@rspress/plugin-llms": "2.0.0-beta.16",
32
32
  "@types/fs-extra": "9.0.13",
33
33
  "@types/node": "^16",
34
34
  "classnames": "^2.5.1",
35
35
  "clsx": "^1.2.1",
36
- "fs-extra": "^10",
36
+ "fs-extra": "^10.1.0",
37
37
  "react": "^18.3.1",
38
38
  "react-dom": "^18.3.1",
39
- "rspress": "2.0.0-beta.11",
39
+ "rspress": "2.0.0-beta.16",
40
40
  "ts-node": "^10.9.1",
41
41
  "typescript": "^5"
42
42
  },