@modern-js/main-doc 2.46.1 → 2.47.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. package/docs/en/apis/app/commands.mdx +9 -9
  2. package/docs/en/configure/app/auto-load-plugin.mdx +3 -3
  3. package/docs/en/configure/app/builder-plugins.mdx +13 -13
  4. package/docs/en/configure/app/output/disable-node-polyfill.mdx +1 -1
  5. package/docs/en/configure/app/server/ssr.mdx +1 -1
  6. package/docs/en/configure/app/source/enable-async-entry.mdx +1 -1
  7. package/docs/en/configure/app/tools/esbuild.mdx +7 -7
  8. package/docs/en/guides/advanced-features/compatibility.mdx +1 -1
  9. package/docs/en/guides/advanced-features/optimize-bundle.mdx +7 -7
  10. package/docs/en/guides/advanced-features/rsbuild-plugin.mdx +51 -0
  11. package/docs/en/guides/advanced-features/rspack-start.mdx +1 -3
  12. package/docs/en/guides/advanced-features/using-storybook.mdx +202 -20
  13. package/docs/en/guides/basic-features/css.mdx +2 -2
  14. package/docs/en/guides/concept/builder.mdx +23 -25
  15. package/docs/en/guides/get-started/tech-stack.mdx +1 -1
  16. package/docs/en/guides/topic-detail/framework-plugin/introduction.mdx +1 -1
  17. package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +35 -4
  18. package/docs/zh/apis/app/commands.mdx +9 -9
  19. package/docs/zh/configure/app/auto-load-plugin.mdx +3 -3
  20. package/docs/zh/configure/app/builder-plugins.mdx +14 -14
  21. package/docs/zh/configure/app/output/disable-node-polyfill.mdx +1 -1
  22. package/docs/zh/configure/app/server/ssr.mdx +1 -1
  23. package/docs/zh/configure/app/tools/esbuild.mdx +7 -7
  24. package/docs/zh/guides/advanced-features/compatibility.mdx +1 -1
  25. package/docs/zh/guides/advanced-features/optimize-bundle.mdx +8 -8
  26. package/docs/zh/guides/advanced-features/rsbuild-plugin.mdx +51 -0
  27. package/docs/zh/guides/advanced-features/rspack-start.mdx +1 -1
  28. package/docs/zh/guides/advanced-features/using-storybook.mdx +204 -21
  29. package/docs/zh/guides/basic-features/css.mdx +2 -2
  30. package/docs/zh/guides/concept/builder.mdx +20 -22
  31. package/docs/zh/guides/get-started/tech-stack.mdx +1 -1
  32. package/docs/zh/guides/topic-detail/framework-plugin/introduction.mdx +1 -1
  33. package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +35 -6
  34. package/package.json +7 -7
  35. package/docs/en/configure/app/source/compile-js-data-uri.mdx +0 -9
  36. package/docs/zh/configure/app/source/compile-js-data-uri.mdx +0 -9
@@ -195,7 +195,7 @@ Options:
195
195
 
196
196
  ## modern inspect
197
197
 
198
- The `modern inspect` command is used to view the [Modern.js Builder config](https://modernjs.dev/builder/en/guide/basic/builder-config.html) and webpack config of the project.
198
+ The `modern inspect` command is used to view the [Rsbuild config](https://rsbuild.dev/config/index) and webpack or Rspack config of the project.
199
199
 
200
200
  ```bash
201
201
  Usage: modern inspect [options]
@@ -210,16 +210,16 @@ Options:
210
210
 
211
211
  After executing the command `npx modern inspect` in the project root directory, the following files will be generated in the `dist` directory of the project:
212
212
 
213
- - `builder.config.js`: The Modern.js Builder config to use at build time.
214
- - `webpack.config.web.js`: The webpack config used by to use at build time.
213
+ - `rsbuild.config.mjs`: The Rsbuild config to use at build time.
214
+ - `webpack.config.web.mjs`: The webpack config used by to use at build time.
215
215
 
216
216
  ```bash
217
217
  ➜ npx modern inspect
218
218
 
219
219
  Inspect config succeed, open following files to view the content:
220
220
 
221
- - Builder Config: /root/my-project/dist/builder.config.js
222
- - Webpack Config (web): /root/my-project/dist/webpack.config.web.js
221
+ - Rsbuild Config: /root/my-project/dist/rsbuild.config.mjs
222
+ - Webpack Config (web): /root/my-project/dist/webpack.config.web.mjs
223
223
  ```
224
224
 
225
225
  ### Configuration Env
@@ -240,16 +240,16 @@ modern inspect --verbose
240
240
 
241
241
  ### SSR Configuration
242
242
 
243
- If the project has enabled SSR, an additional `webpack.config.node.js` file will be generated in the `dist/`, corresponding to the webpack configuration at SSR build time.
243
+ If the project has enabled SSR, an additional `webpack.config.node.mjs` file will be generated in the `dist/`, corresponding to the webpack configuration at SSR build time.
244
244
 
245
245
  ```bash
246
246
  ➜ npx modern inspect
247
247
 
248
248
  Inspect config succeed, open following files to view the content:
249
249
 
250
- - Builder Config: /root/my-project/dist/builder.config.js
251
- - Webpack Config (web): /root/my-project/dist/webpack.config.web.js
252
- - Webpack Config (node): /root/my-project/dist/webpack.config.node.js
250
+ - Rsbuild Config: /root/my-project/dist/rsbuild.config.mjs
251
+ - Webpack Config (web): /root/my-project/dist/webpack.config.web.mjs
252
+ - Webpack Config (node): /root/my-project/dist/webpack.config.node.mjs
253
253
  ```
254
254
 
255
255
  ## modern lint
@@ -39,14 +39,14 @@ Modern.js will help you automatically register the plugin by following these ste
39
39
  1. Modern.js maintains an official list of plugins internally.
40
40
 
41
41
  ```js
42
- const InternalPlugins = ['@modern-js/app-tools', '@modern-js/plugin-i18n', ...];
42
+ const InternalPlugins = ['@modern-js/app-tools', '@modern-js/plugin-tailwindcss', ...];
43
43
  ```
44
44
 
45
45
  2. Modern.js will read your `package.json` and collect the dependency information.
46
46
 
47
47
  ```json title="package.json"
48
48
  "dependencies": {
49
- "@modern-js/plugin-i18n": "x.x.x"
49
+ "@modern-js/plugin-tailwindcss": "x.x.x"
50
50
  ...
51
51
  },
52
52
  "devDependencies": {
@@ -55,7 +55,7 @@ const InternalPlugins = ['@modern-js/app-tools', '@modern-js/plugin-i18n', ...];
55
55
  }
56
56
  ```
57
57
 
58
- 3. Modern.js observes that when you install dependencies such as `@modern-js/plugin-i18n` and `@modern-js/app-tools`, automatic plugin registration will be imported.
58
+ 3. Modern.js observes that when you install dependencies such as `@modern-js/plugin-tailwindcss` and `@modern-js/app-tools`, automatic plugin registration will be imported.
59
59
 
60
60
  You can notice that this approach is relatively black-box and you are not even aware of the process of loading the plugin. We want to expose more details to the developer and be able to let the developer control the process.
61
61
 
@@ -4,16 +4,16 @@ sidebar_position: 21
4
4
 
5
5
  # builderPlugins
6
6
 
7
- - **Type:** `BuilderPlugin[]`
7
+ - **Type:** `RsbuildPlugin[]`
8
8
  - **Default:** `[]`
9
9
 
10
- Used to configure the Modern.js Builder plugin.
10
+ Used to configure the Rsbuild plugin.
11
11
 
12
- Modern.js Builder is the build tool of Modern.js, please read [Builder](/guides/concept/builder) for background. If you want to know how to write Builder plugins, you can refer to [Modern.js Builder - Introduce to Plugin](https://modernjs.dev/builder/en/plugins/introduction.html).
12
+ Rsbuild is the build tool of Modern.js, please read [Build Engine](/guides/concept/builder) for background. If you want to know how to write Rsbuild plugins, you can refer to [Rsbuild - Plugin System](https://rsbuild.dev/plugins/dev/index).
13
13
 
14
14
  ## Precautions
15
15
 
16
- This option **is used to configure the Modern.js Builder plugins**. If you need to configure other types of plugins, please select the corresponding configs:
16
+ This option **is used to configure the Rsbuild plugins**. If you need to configure other types of plugins, please select the corresponding configs:
17
17
 
18
18
  - Use [plugins](/configure/app/plugins) to configure Modern.js framework plugins.
19
19
  - Use [tools.bundlerChain](/configure/app/tools/bundler-chain) to configure Rspack or webpack plugins.
@@ -21,23 +21,23 @@ This option **is used to configure the Modern.js Builder plugins**. If you need
21
21
 
22
22
  ## When to use
23
23
 
24
- In most scenarios, we recommend you to use the Modern.js framework plugin, which can be registered through the [plugins](/configure/app/plugins) config. Because the API provided by the framework plugin is richer and more capable, while the API provided by the Builder plugin can only be used to build scenes.
24
+ In most scenarios, we recommend you to use the Modern.js framework plugin, which can be registered through the [plugins](/configure/app/plugins) config. Because the API provided by the framework plugin is richer and more capable, while the API provided by the Rsbuild plugin can only be used to build scenes.
25
25
 
26
- When you need to reference some existing Builder plugins (and there is no related capability in Modern.js), or reuse Builder plugins between different frameworks, you can use the `builderPlugins` field to register them.
26
+ When you need to reference some existing Rsbuild plugins (and there is no related capability in Modern.js), or reuse Rsbuild plugins between different frameworks, you can use the `builderPlugins` field to register them.
27
27
 
28
28
  ## Example
29
29
 
30
- Below is an example of using the Builder plugin.
30
+ Below is an example of using the Rsbuild plugin.
31
31
 
32
32
  ### Using plugins on npm
33
33
 
34
34
  To use a plugin on npm, you need to install the plugin through the package manager and import it.
35
35
 
36
36
  ```ts title="modern.config.ts"
37
- import myBuilderPlugin from 'my-builder-plugin';
37
+ import myRsbuildPlugin from 'my-rsbuild-plugin';
38
38
 
39
39
  export default defineConfig({
40
- builderPlugins: [myBuilderPlugin()],
40
+ builderPlugins: [myRsbuildPlugin()],
41
41
  });
42
42
  ```
43
43
 
@@ -46,10 +46,10 @@ export default defineConfig({
46
46
  Use the plugin in the local code repository, you can import it directly through the relative path import.
47
47
 
48
48
  ```ts title="modern.config.ts"
49
- import myBuilderPlugin from './plugin/myBuilderPlugin';
49
+ import myRsbuildPlugin from './plugin/myRsbuildPlugin';
50
50
 
51
51
  export default defineConfig({
52
- builderPlugins: [myBuilderPlugin()],
52
+ builderPlugins: [myRsbuildPlugin()],
53
53
  });
54
54
  ```
55
55
 
@@ -58,11 +58,11 @@ export default defineConfig({
58
58
  If the plugin provides some custom configuration options, you can pass in the configuration through the parameters of the plugin function.
59
59
 
60
60
  ```ts title="modern.config.ts"
61
- import myBuilderPlugin from 'my-builder-plugin';
61
+ import myRsbuildPlugin from 'my-rsbuild-plugin';
62
62
 
63
63
  export default defineConfig({
64
64
  builderPlugins: [
65
- myBuilderPlugin({
65
+ myRsbuildPlugin({
66
66
  foo: 1,
67
67
  bar: 2,
68
68
  }),
@@ -19,4 +19,4 @@ export default defineConfig({
19
19
  });
20
20
  ```
21
21
 
22
- This config is implemented based on the Node Polyfill plugin of Modern.js Builder, you can read [Modern.js Builder - Node Polyfill Plugin](https://modernjs.dev/builder/en/plugins/plugin-node-polyfill.html) documentation for details.
22
+ This config is implemented based on the Node Polyfill plugin of Rsbuild, you can read [Rsbuild - Node Polyfill Plugin](https://rsbuild.dev/plugins/list/plugin-node-polyfill) documentation for details.
@@ -27,7 +27,7 @@ When the value type is `Object`, the following properties can be configured:
27
27
 
28
28
  - `mode`: `string = 'string'`, which defaults to using `renderToString` for rendering. Configure `stream` to enable streaming rendering.
29
29
  - `forceCSR`: `boolean = false`, which is off by default for forcing CSR rendering. Configure `true` to force CSR by adding `?csr=true` or adding `x-modern-ssr-fallback` header when accessing the page.
30
- - `inlineScript`: `boolean = true`, by default, SSR data is injected into HTML as inline scripts and assigned directly to global variables. Configure `false` to distribute JSON instead of assigning to global variables.
30
+ - `inlineScript`: `boolean = true`, by default, SSR data is injected into HTML as inline scripts and assigned directly to global variables. Configure `false` to distribute JSON instead of assigning to global variables, this configuration doesn't work in Streaming SSR.
31
31
  - `disablePrerender`: `boolean = fasle`, To ensure compatibility with the old data request method (`useLoader`), by default, Modern.js performs pre-rendering of components.
32
32
  However, if developers want to reduce one rendering when there is no use of the useLoader API in your project, you can set the configuration `disablePrerender=true`.
33
33
  - `unsafeHeaders`: `string[] = []`, For safety reasons, Modern.js does not add excessive content to SSR_DATA. Developers can use this configuration to specify the headers that need to be injected.
@@ -13,7 +13,7 @@ When this option is enabled, Modern.js will wrap the automatically generated ent
13
13
 
14
14
  ## Background
15
15
 
16
- import ModuleFederation from '@modern-js/builder-doc/docs/zh/shared/module-federation.md';
16
+ import ModuleFederation from '@modern-js/builder-doc/docs/en/shared/module-federation.md';
17
17
 
18
18
  <ModuleFederation />
19
19
 
@@ -7,18 +7,18 @@ sidebar_label: esbuild
7
7
  - **Type:** `Object`
8
8
  - **Default:** `undefined`
9
9
 
10
- ## Introduction
10
+ :::warning
11
+ **The esbuild feature in the current document is no longer maintained**, we recommend using the Rspack + SWC solution, because Rspack + SWC provide better build performance, richer features, and better compatibility.
11
12
 
12
- import Esbuild from '@modern-js/builder-doc/docs/en/shared/esbuild.md';
13
+ Please refer to [「Use Rspack」](/guides/advanced-features/rspack-start.html) for more information.
13
14
 
14
- <Esbuild />
15
+ :::
15
16
 
16
- :::tip Recommend using SWC
17
- We recommend using SWC to transform and minify code rather than esbuild, because SWC supports more syntaxes, provides better code compression, and the compiled code has better compatibility.
17
+ ## Introduction
18
18
 
19
- Therefore, we recommend that you use SWC instead of esbuild, please refer to [tools.swc](/configure/app/tools/swc) for usage.
19
+ import Esbuild from '@modern-js/builder-doc/docs/en/shared/esbuild.md';
20
20
 
21
- :::
21
+ <Esbuild />
22
22
 
23
23
  ## Configuration
24
24
 
@@ -19,7 +19,7 @@ ios_saf >= 10
19
19
  ```
20
20
 
21
21
  :::tip
22
- Please refer to [Modern.js Builder - Browserslist](https://modernjs.dev/builder/en/guide/advanced/browserslist) for more information.
22
+ Please refer to [Rsbuild - Browserslist](https://rsbuild.dev/guide/advanced/browserslist) for more information.
23
23
  :::
24
24
 
25
25
  ## Polyfill
@@ -4,7 +4,7 @@ sidebar_position: 13
4
4
 
5
5
  # Bundle Size Optimization
6
6
 
7
- Bundle size optimization is an important part in production environment because it directly affects the user experience of online users. In this document, we will introduce some common bundle size optimization methods in Builder.
7
+ Bundle size optimization is an important part in production environment because it directly affects the user experience of online users. In this document, we will introduce some common bundle size optimization methods in Modern.js.
8
8
 
9
9
  ## Reduce duplicate dependencies
10
10
 
@@ -59,7 +59,7 @@ For example, if you only need to be compatible with browsers above Chrome 61, yo
59
59
  ```
60
60
 
61
61
  :::tip
62
- Please read the [Browserslist](https://modernjs.dev/builder/en/guide/advanced/browserslist.html) chapter to know more about the usage of Browserslist.
62
+ Please read the [Browserslist](https://rsbuild.dev/guide/advanced/browserslist) chapter to know more about the usage of Browserslist.
63
63
  :::
64
64
 
65
65
  ## Usage polyfill
@@ -82,23 +82,23 @@ Please read the [Browser Compatibility](/guides/advanced-features/compatibility)
82
82
 
83
83
  ## Image Compression
84
84
 
85
- In general front-end projects, the size of image often accounts for a large proportion of the total bundle size of the project.So if the image size can be reduced as much as possible, it will have a significant optimization effect on the project bundle size. You can enable image compression by registering a plugin in the Builder:
85
+ In general front-end projects, the size of image often accounts for a large proportion of the total bundle size of the project.So if the image size can be reduced as much as possible, it will have a significant optimization effect on the project bundle size. You can enable image compression by registering a plugin in Modern.js:
86
86
 
87
87
  ```ts title="modern.config.ts"
88
- import { builderPluginImageCompress } from '@modern-js/builder-plugin-image-compress';
88
+ import { pluginImageCompress } from '@rsbuild/plugin-image-compress';
89
89
 
90
90
  export default {
91
- builderPlugins: [builderPluginImageCompress()],
91
+ builderPlugins: [pluginImageCompress()],
92
92
  };
93
93
  ```
94
94
 
95
- See details in [plugin-image-compress](https://modernjs.dev/builder/en/plugins/plugin-image-compress.html).
95
+ See details in [plugin-image-compress](https://rsbuild.dev/plugins/list/plugin-image-compress).
96
96
 
97
97
  ## Split Chunk
98
98
 
99
99
  A great chunk splitting strategy is very important to improve the loading performance of the application. It can make full use of the browser's caching mechanism to reduce the number of requests and improve the loading speed of the application.
100
100
 
101
- A variety of [chunk splitting strategies](https://modernjs.dev/builder/en/guide/optimization/split-chunk) are built into Builder, which can meet the needs of most applications. You can also customize the chunk splitting config according to your own business scenarios.
101
+ A variety of [chunk splitting strategies](https://rsbuild.dev/guide/optimization/split-chunk) are built into Modern.js, which can meet the needs of most applications. You can also customize the chunk splitting config according to your own business scenarios.
102
102
 
103
103
  For example, split the `axios` library under node_modules into `axios.js`:
104
104
 
@@ -0,0 +1,51 @@
1
+ ---
2
+ sidebar_position: 21
3
+ title: Using Rsbuild Plugin
4
+ ---
5
+
6
+ # Using Rsbuild Plugin
7
+
8
+ ## Introduce Rsbuild Plugin
9
+
10
+ Rsbuild is the build tool of Modern.js. You can modify the default build behavior and add various additional features by adding the Rsbuild plugin, including but not limited to:
11
+
12
+ - Modifying Rspack configurations
13
+ - Processing new file types
14
+ - Modifying or compiling files
15
+ - Deploying artifacts
16
+
17
+ You can register the Rsbuild plugin through the `builderPlugins` option in `modern.config.ts`, see [builderPlugins](/configure/app/builder-plugins) for details.
18
+
19
+ ## Official Plugins
20
+
21
+ :::tip
22
+ Most plugins in Rsbuild have been built into Modern.js. For example, when you need to inject the Polyfill of the Node module, you can directly use the [output.disableNodePolyfill](/configure/app/output/disable-node-polyfill.html) configuration.
23
+ :::
24
+
25
+ ### Builtin Plugins
26
+
27
+ Here are the official Rsbuild plugins built into Modern.js:
28
+
29
+ | Plugin Name | Introduce | Modern.js Link |
30
+ | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
31
+ | [React Plugin](https://rsbuild.dev/plugins/list/plugin-react) | Provides support for React | - |
32
+ | [SVGR Plugin](https://rsbuild.dev/plugins/list/plugin-svgr) | Support convert SVG to React components | [output.disableSvgr](/configure/app/output/disable-svgr)<br />[output.svgDefaultExport](/configure/app/output/svg-default-export) |
33
+ | [Styled Components Plugin](https://rsbuild.dev/plugins/list/plugin-styled-components) | Provides compile-time support for styled-components | [tools.styledComponents](/configure/app/tools/styled-components.html) |
34
+ | [Assets Retry Plugin](https://rsbuild.dev/plugins/list/plugin-assets-retry) | Used to automatically resend requests when static assets fail to load | [output.assetsRetry](/configure/app/output/assets-retry.html) |
35
+ | [Type Check Plugin](https://rsbuild.dev/plugins/list/plugin-type-check) | Used to run TypeScript type checker on a separate process | [output.disableTsChecker](/configure/app/output/disable-ts-checker.html)<br />[tools.tsChecker](/configure/app/tools/ts-checker.html) |
36
+ | [Node Polyfill Plugin](https://rsbuild.dev/plugins/list/plugin-node-polyfill) | Used to inject polyfills of Node core modules in the browser side | [output.disableNodePolyfill](/configure/app/output/disable-node-polyfill.html) |
37
+ | [Source Build Plugin](https://rsbuild.dev/plugins/list/plugin-source-build) | Supports referencing source code from other subdirectories | [experiments.sourceBuild](/configure/app/experiments/source-build.html) |
38
+ | [Check Syntax Plugin](https://rsbuild.dev/plugins/list/plugin-check-syntax) | Used to analyze the syntax compatibility of artifacts | [security.checkSyntax](/configure/app/security/check-syntax.html) |
39
+ | [CSS Minimizer Plugin](https://rsbuild.dev/plugins/list/plugin-css-minimizer) | Used to customize CSS minimizer, switch to [cssnano](https://cssnano.co/) or other tools for CSS compression | [tools.minifyCss](/configure/app/tools/minify-css.html) |
40
+ | [Pug Plugin](https://rsbuild.dev/plugins/list/plugin-pug) | Provides support for the Pug template engine | [tools.pug](/configure/app/tools/pug.html) |
41
+ | [Rem Plugin](https://rsbuild.dev/plugins/list/plugin-rem) | Implements the rem adaptive layout for mobile pages | [output.convertToRem](/configure/app/output/convert-to-rem.html) |
42
+ | [YAML Plugin](https://rsbuild.dev/plugins/list/plugin-yaml) | Used to import YAML files and convert them into JavaScript objects | [TOML File](/guides/basic-features/json-files.html#toml-file) |
43
+ | [TOML Plugin](https://rsbuild.dev/plugins/list/plugin-toml) | Used to import TOML files and convert them into JavaScript objects | [YAML File](/guides/basic-features/json-files.html#yaml-file) |
44
+
45
+ ### Un-builtin Plugins
46
+
47
+ Here are the official Rsbuild plugins that are not built into Modern.js:
48
+
49
+ - [Image Compress Plugin](https://rsbuild.dev/plugins/list/plugin-image-compress): Compress the image resources used in the project.
50
+ - [Stylus Plugin](https://rsbuild.dev/plugins/list/plugin-stylus): Use Stylus as the CSS preprocessor.
51
+ - [UMD Plugin](https://rsbuild.dev/plugins/list/plugin-umd): Used to build outputs in UMD format.
@@ -55,14 +55,12 @@ import RspackPrecautions from '@modern-js/builder-doc/docs/en/shared/rspackPreca
55
55
 
56
56
  ## Migrating configuration
57
57
 
58
- After enabling Rspack building capability, further configuration migration is needed by referring to the [Configuration Differences](https://modernjs.dev/builder/en/guide/advanced/rspack-start.html#migrating-from-webpack-to-rspack).
59
-
60
58
  In Modern.js, the [tools.webpack](/configure/app/tools/webpack) and [tools.webpackChain](/configure/app/tools/webpack-chain) configurations only take effect in webpack mode, after turning on the Rspack build, you can modify it to [tools.rspack](/configure/app/tools/rspack) and [tools.bundlerChain](/configure/app/tools/bundler-chain).
61
59
 
62
60
  ```diff
63
61
  export default {
64
62
  tools: {
65
- - webppack: (config, { env }) => {
63
+ - webpack: (config, { env }) => {
66
64
  + rspack: (config, { env }) => {
67
65
  if (env === 'development') {
68
66
  config.devtool = 'cheap-module-eval-source-map';
@@ -2,11 +2,7 @@
2
2
  sidebar_position: 15
3
3
  ---
4
4
 
5
- # Using StorybookV6
6
-
7
- :::warning
8
- This document is for users of the old version Storybook V6 and will be deprecated in the future. If you want to upgrade from an older version or if you are a new user who wants to try new storybook, please refer to the [new documentation here](https://modernjs.dev/builder/guide/advanced/storybook.html).
9
- :::
5
+ # Using Storybook
10
6
 
11
7
  [Storybook](https://storybook.js.org/) is a tool dedicated to component debugging, providing around component development.
12
8
 
@@ -16,33 +12,219 @@ This document is for users of the old version Storybook V6 and will be deprecate
16
12
  - Share how the UI actually works
17
13
  - Automate UI workflows
18
14
 
19
- ## Enable Storybook debugging
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
+ :::
20
18
 
21
- The Modern.js framework integrates the Builder's Node Polyfill plugin by default.
19
+ ## Quick Start
22
20
 
23
- If you want to debug the component, you can enable Storybook debugging through `pnpm run new`.
21
+ Modern.js integrates Storybook debugging capabilities by default. You can directly enable the Storybook feature by using the following command:
24
22
 
25
23
  ```bash
26
24
  $ npx modern new
27
25
  ? Please select the operation you want: Enable features
28
- ? Please select the feature name: Enable Visual Testing (Storybook)
26
+ ? Please select the feature name: EnableStorybook」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
110
+
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;
29
177
  ```
30
178
 
31
- After the execution is complete, you only need to register the Modern.js Storybook plugin in the `modern.config.ts` file to enable Storybook debugging capabilities.
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:
32
184
 
33
- ```ts title="modern.config.ts"
34
- import { appTools, defineConfig } from '@modern-js/app-tools';
35
- import { storybookPlugin } from '@modern-js/plugin-storybook';
185
+ ##### Modify configuration file
36
186
 
37
- export default defineConfig({
38
- plugins: [appTools(), storybookPlugin()],
39
- });
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`.
190
+
191
+ ```diff
192
+ const config = {
193
+ + framework: {
194
+ + name: '@modern-js/storybook'
195
+ + }
196
+ };
197
+
198
+ export default config;
40
199
  ```
41
200
 
42
- ## Debugging code
201
+ ##### Update Dependencies
202
+
203
+ Update dependencies like @storybook/addon-\* to major version 7.
43
204
 
44
- Modern.js recognizes files in the format of [\*.stories.(js|jsx|ts|tsx|mdx)](/apis/app/hooks/src/stories.html) under the project source code directory (src/) by default as Storybook debugging files.
205
+ ##### Remove @modern-js/plugin-storybook
206
+
207
+ 在 modern.config.(j|t)s 中删除 @modern-js/plugin-storybook 插件的注册。
208
+
209
+ ##### Modify Storybook Syntax
210
+
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).
212
+
213
+ ### Native Storybook users
214
+
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).
216
+
217
+ ```diff filename='.storybook/main.js'
218
+ const config = {
219
+ - framework: '@storybook/react-webapck5',
220
+ + framework: {
221
+ + name: '@modern-js/storybook'
222
+ + },
223
+ };
224
+
225
+ export default config;
226
+ ```
45
227
 
46
- ## Configure Storybook
228
+ The default config file path is `modern.config.(j|t)s`, for the detail config, see [modern.js config](/configure/app/usage).
47
229
 
48
- In Modern.js, Storybook configuration files can be added to the [`config/storybook`](/apis/app/hooks/config/storybook.html) directory of the project.
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.
@@ -12,13 +12,13 @@ Modern.js has built-in popular community CSS preprocessors, including Less and S
12
12
 
13
13
  By default, you don't need to configure Less and Sass. If you have custom loader configuration requirements, you can set them up by configuring [tools.less](/configure/app/tools/less) and [tools.sass](/configure/app/tools/sass).
14
14
 
15
- You can also use Stylus in Modern.js by installing the Stylus plugin provided by Modern.js Builder. For usage, please refer to [Stylus Plugin](https://modernjs.dev/builder/plugins/plugin-stylus.html).
15
+ You can also use Stylus in Modern.js by installing the Stylus plugin provided by Rsbuild. For usage, please refer to [Stylus Plugin](https://rsbuild.dev/plugins/list/plugin-stylus).
16
16
 
17
17
  ## Using PostCSS
18
18
 
19
19
  Modern.js has built-in [PostCSS](https://postcss.org/) to transform CSS code.
20
20
 
21
- Please refer to [Modern.js Builder - Using PostCSS](https://modernjs.dev/builder/en/guide/basic/css-usage.html#using-postcss) for detailed usage.
21
+ Please refer to [Rsbuild - Using PostCSS](https://rsbuild.dev/guide/basic/css-usage#using-postcss) for detailed usage.
22
22
 
23
23
  ## Using CSS Modules
24
24