@modern-js/main-doc 2.22.1 → 2.23.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/docs/en/apis/app/commands.mdx +5 -5
  3. package/docs/en/apis/app/hooks/config/storybook.mdx +24 -0
  4. package/docs/en/apis/app/hooks/src/stories.mdx +1 -1
  5. package/docs/en/apis/app/runtime/core/bootstrap.mdx +5 -5
  6. package/docs/en/apis/app/runtime/core/use-loader.mdx +2 -2
  7. package/docs/en/apis/app/runtime/core/use-module-apps.mdx +2 -2
  8. package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +1 -1
  9. package/docs/en/apis/app/runtime/testing/render.mdx +1 -1
  10. package/docs/en/components/bff-proxy-path-rewrite.mdx +16 -0
  11. package/docs/en/components/bff-proxy-principle.mdx +1 -0
  12. package/docs/en/components/enable-bff-caution.mdx +3 -0
  13. package/docs/en/components/global-proxy-config.mdx +33 -13
  14. package/docs/en/configure/app/bff/enable-handle-web.mdx +5 -5
  15. package/docs/en/configure/app/bff/prefix.mdx +6 -6
  16. package/docs/en/configure/app/bff/proxy.mdx +19 -30
  17. package/docs/en/configure/app/builder-plugins.mdx +1 -1
  18. package/docs/en/configure/app/plugins.mdx +19 -19
  19. package/docs/en/configure/app/runtime/intro.mdx +28 -4
  20. package/docs/en/configure/app/runtime/master-app.mdx +1 -1
  21. package/docs/en/configure/app/runtime/router.mdx +2 -2
  22. package/docs/en/configure/app/server/base-url.mdx +4 -4
  23. package/docs/en/configure/app/server/enable-framework-ext.mdx +4 -4
  24. package/docs/en/configure/app/server/port.mdx +6 -6
  25. package/docs/en/configure/app/server/public-routes.mdx +5 -5
  26. package/docs/en/configure/app/server/routes.mdx +13 -13
  27. package/docs/en/configure/app/server/ssr-by-entries.mdx +4 -4
  28. package/docs/en/configure/app/server/ssr.mdx +5 -5
  29. package/docs/en/configure/app/testing/transformer.mdx +4 -8
  30. package/docs/en/configure/app/usage.mdx +5 -5
  31. package/docs/en/guides/advanced-features/code-split.mdx +15 -14
  32. package/docs/en/guides/advanced-features/compatibility.mdx +3 -24
  33. package/docs/en/guides/advanced-features/rspack-start.mdx +0 -1
  34. package/docs/en/guides/advanced-features/ssr.mdx +2 -2
  35. package/docs/en/guides/advanced-features/testing.mdx +8 -7
  36. package/docs/en/guides/advanced-features/using-storybook.mdx +44 -0
  37. package/docs/en/guides/advanced-features/web-server.mdx +16 -16
  38. package/docs/en/guides/basic-features/alias.mdx +11 -9
  39. package/docs/en/guides/basic-features/env-vars.mdx +14 -14
  40. package/docs/en/guides/basic-features/html.mdx +41 -43
  41. package/docs/en/guides/basic-features/mock.mdx +10 -10
  42. package/docs/en/guides/topic-detail/framework-plugin/implement.mdx +4 -4
  43. package/docs/en/guides/topic-detail/framework-plugin/introduction.mdx +1 -1
  44. package/docs/en/guides/troubleshooting/cli.mdx +13 -13
  45. package/docs/en/guides/troubleshooting/dependencies.mdx +25 -25
  46. package/docs/en/tutorials/first-app/c03-css.mdx +1 -1
  47. package/docs/zh/apis/app/commands.mdx +4 -4
  48. package/docs/zh/apis/app/hooks/config/storybook.mdx +24 -0
  49. package/docs/zh/apis/app/hooks/src/stories.mdx +1 -1
  50. package/docs/zh/apis/app/runtime/testing/render.mdx +1 -1
  51. package/docs/zh/components/bff-proxy-path-rewrite.mdx +16 -0
  52. package/docs/zh/components/bff-proxy-principle.mdx +1 -0
  53. package/docs/zh/components/enable-bff-caution.mdx +4 -0
  54. package/docs/zh/components/global-proxy-config.mdx +35 -11
  55. package/docs/zh/configure/app/bff/enable-handle-web.mdx +3 -3
  56. package/docs/zh/configure/app/bff/prefix.mdx +2 -3
  57. package/docs/zh/configure/app/bff/proxy.mdx +11 -21
  58. package/docs/zh/configure/app/runtime/intro.mdx +1 -1
  59. package/docs/zh/configure/app/server/base-url.mdx +1 -1
  60. package/docs/zh/configure/app/server/public-routes.mdx +2 -2
  61. package/docs/zh/configure/app/server/routes.mdx +2 -2
  62. package/docs/zh/configure/app/server/ssr-by-entries.mdx +3 -3
  63. package/docs/zh/configure/app/server/ssr.mdx +1 -1
  64. package/docs/zh/configure/app/testing/transformer.mdx +6 -3
  65. package/docs/zh/configure/app/usage.mdx +9 -9
  66. package/docs/zh/guides/advanced-features/code-split.mdx +13 -12
  67. package/docs/zh/guides/advanced-features/rspack-start.mdx +0 -1
  68. package/docs/zh/guides/advanced-features/ssr.mdx +2 -2
  69. package/docs/zh/guides/advanced-features/testing.mdx +4 -4
  70. package/docs/zh/guides/advanced-features/using-storybook.mdx +44 -0
  71. package/docs/zh/guides/basic-features/alias.mdx +5 -3
  72. package/docs/zh/guides/basic-features/html.mdx +9 -9
  73. package/docs/zh/guides/basic-features/mock.mdx +2 -2
  74. package/docs/zh/guides/topic-detail/_category_.json +1 -1
  75. package/docs/zh/guides/troubleshooting/cli.mdx +1 -1
  76. package/docs/zh/guides/troubleshooting/dependencies.mdx +1 -1
  77. package/package.json +7 -6
@@ -7,13 +7,13 @@ sidebar_label: baseUrl
7
7
  - **Type:** `string | string[]`
8
8
  - **Default:** `undefined`
9
9
 
10
- Uniformly set the server-level routing prefix (often used in the case of shared domain names to distinguish traffic).
10
+ Uniformly set the prefix of server-side routes (commonly used in situations where multiple applications share the same domain name to distinguish traffic).
11
11
 
12
12
  ```ts title="modern.config.ts"
13
13
  export default defineConfig({
14
14
  server: {
15
- // All generated routes are automatically prefixed with `/base`
16
- // Path to the generated server-side route file: dist/route.json
15
+ // All generated routes will automatically have the prefix `/base`
16
+ // Generated server-side route file path: dist/route.json
17
17
  baseUrl: '/base'
18
18
 
19
19
  // Multiple baseUrl
@@ -22,7 +22,7 @@ export default defineConfig({
22
22
  })
23
23
  ```
24
24
 
25
- After `dev`, you can see that the routed access will be prefixed accordingly:
25
+ After running `dev`, you will see that the route access will have the corresponding prefix added:
26
26
 
27
27
  ```bash
28
28
  App running at:
@@ -7,9 +7,9 @@ sidebar_label: enableFrameworkExt
7
7
  - **Type:** `boolean`
8
8
  - **Default:** `false`
9
9
 
10
- By default, with [Custom Web Server](/guides/advanced-features/web-server) enabled, Middleware uses the syntax of the Modern.js itself.
10
+ By default, when the [custom Web Server feature](/guides/advanced-features/web-server) is enabled, the Middleware will use the Modern.js's syntax.
11
11
 
12
- Enable `server.enableFrameworkExt` to use the syntax of framework extensions.
12
+ Enabling `server.enableFrameworkExt` allows the use of syntax extensions from other frameworks.
13
13
 
14
14
  ```ts title="modern.config.ts"
15
15
  export default defineConfig({
@@ -32,7 +32,7 @@ export const middleware: Middleware = (ctx, next) => {
32
32
  };
33
33
  ```
34
34
 
35
- When enabled, Middleware types will be exported from other namespaces and can the syntax of framework extensions:
35
+ After enabling it, the Middleware type will be exported from other namespaces, and syntax extensions from frameworks can be used:
36
36
 
37
37
  ```ts title="server/index.ts"
38
38
  import { SomeType } from '@modern-js/runtime/{namespace}';
@@ -44,6 +44,6 @@ export const middleware: SomeType = (...args) => {
44
44
  ```
45
45
 
46
46
  :::note
47
- The above code is pseudo-code, and the specific usage needs to refer to the corresponding framework extension.
47
+ The above code is pseudocode, and the specific usage needs to refer to the corresponding framework extension.
48
48
 
49
49
  :::
@@ -7,7 +7,7 @@ sidebar_label: port
7
7
  - **Type:** `number`
8
8
  - **Default:** `8080`
9
9
 
10
- When Modern.js executes `dev`, `start` and `serve` commands, it will start with `8080` as the default port, and will automatically increment the port number when the port is occupied. You can change the port number of Server through this config:
10
+ When running the `dev`, `start`, and `serve` commands, Modern.js will start with `8080` as the default port and automatically increase the port number when the port is occupied. You can use this configuration to modify the port number that the Server starts with:
11
11
 
12
12
  ```js title="modern.config.ts"
13
13
  export default defineConfig({
@@ -17,14 +17,14 @@ export default defineConfig({
17
17
  });
18
18
  ```
19
19
 
20
- ### Difference with dev.port
20
+ ### Difference between `server.port` and `dev.port`
21
21
 
22
- In most cases, we recommend using `server.port` instead of `dev.port` to set the port number, the differences between them are as follows:
22
+ In most cases, we recommend using `server.port` instead of `dev.port` to set the port number, and the differences between them are as follows:
23
23
 
24
- - `dev.port` only takes effect in the development, and `server.port` takes effect in both development and production.
25
- - In the development, `dev.port` takes precedence over `server.port`.
24
+ - `dev.port` only works in the development environment, while `server.port` works in both the development and production environments.
25
+ - In the development environment, `dev.port` has a higher priority than `server.port`.
26
26
 
27
- When you set `dev.port` and `server.port` at the same time, `dev.port` will take effect in the development, and `server.port` will take effect in the production. For example, in the following example, the port in the development is `3001`, and the port in the production is `3002`.
27
+ When you set both `dev.port` and `server.port`, `dev.port` will take effect in the development environment, and `server.port` will take effect in the production environment. For example, in the following example, the port number listened to in the development environment is `3001`, and the port number listened to in the production environment is `3002`.
28
28
 
29
29
  ```ts title="modern.config.ts"
30
30
  export default defineConfig({
@@ -5,20 +5,20 @@ sidebar_label: publicRoutes
5
5
  # server.publicRoutes
6
6
 
7
7
  - **Type:** `Object`
8
- - **Default:** Automatic generation of server-level routing rules based on file conventions: One routing rule is generated per file of the application.
8
+ - **Default:** Server-side routing rules generated based on file conventions, with one route rule generated for each file.
9
9
 
10
- This configuration option only applies to server-level routing, and you can customize the access route of resources in `config/public/`.
10
+ This configuration option only applies to server-side routing and can customize the access route of resources under `config/public/`.
11
11
 
12
- The `key` of the object is the relative file path of the current application (not used `./`), value can be `string`.
12
+ The `key` of the object is the relative file path of the `config/public/` (without using `./`), and the value can be a `string`.
13
13
 
14
14
  ```ts title="modern.config.ts"
15
15
  export default defineConfig({
16
16
  server: {
17
17
  publicRoutes: {
18
- // Set up a long route
18
+ // Set a long route
19
19
  'index.json': '/user-config/card-info/extra/help.json',
20
20
 
21
- // Set up a route without a suffix
21
+ // Set a route without a suffix
22
22
  'robot.txt': '/app/authentication',
23
23
  },
24
24
  },
@@ -5,30 +5,30 @@ sidebar_label: routes
5
5
  # server.routes
6
6
 
7
7
  - **Type:** `Object`
8
- - **Default:** Automatic generation of server-level routing rules based on file conventions: One routing rule is generated per file of the application,and the default route is the same as the entry name.
8
+ - **Default:** Server-side routing rules generated based on file conventions, with one route rule generated for each entry, and the entry name is equal to the route path.
9
9
 
10
- This configuration option only applies to server-level routing, and can customize the service access configuration of the application entry.
10
+ This configuration option only applies to server-side routing and can customize the access route of application entries.
11
11
 
12
- ## Custom access routing
12
+ ## Custom access routes
13
13
 
14
- The `key` of the object is the entry name of the current application, and the value can be `string | Array<string>`.
14
+ The `key` of the object is the name of the current application entry, and the value can be a `string | Array<string>`.
15
15
 
16
- When the value type is `string`, the current value represents the name of the route to access the entry.
16
+ When the value type is `string`, the current value represents the route path for accessing the entry.
17
17
 
18
18
  ```ts title="modern.config.ts"
19
19
  export default defineConfig({
20
20
  server: {
21
21
  routes: {
22
- // The default route is /entryName1, /p/test1 after customization
22
+ // Default route is /entryName1, customized to /p/test1
23
23
  entryName1: '/p/test1'
24
- // Support dynamic server-level routing configuration
24
+ // Supports dynamic server-side routing configuration
25
25
  entryName2: '/detail/:id'
26
26
  }
27
27
  }
28
28
  });
29
29
  ```
30
30
 
31
- Multiple access routes can also be set for entries using the `Array<string>`:
31
+ Multiple access routes can also be set for the entry through `Array<string>`:
32
32
 
33
33
  ```ts title="modern.config.ts"
34
34
  export default defineConfig({
@@ -40,9 +40,9 @@ export default defineConfig({
40
40
  });
41
41
  ```
42
42
 
43
- At this point, the '`page-a` entry can be accessed through both `/a` and `/b` routes.
43
+ At this time, the `page-a` entry can be accessed through both the `/a` and `/b` routes.
44
44
 
45
- After executing the `dev` command, you can see in `dist/route.json` that there are two routing records in the entry `page-a`:
45
+ After executing the `dev` command, you can view two route records for the `page-a` entry in `dist/route.json`:
46
46
 
47
47
  ```json
48
48
  {
@@ -65,9 +65,9 @@ After executing the `dev` command, you can see in `dist/route.json` that there a
65
65
  }
66
66
  ```
67
67
 
68
- ## Custom response header
68
+ ## Custom response headers
69
69
 
70
- The response header can be set by configuring the resHeaders of the entry:
70
+ Response headers can be set by configuring the `resHeaders` of the entry:
71
71
 
72
72
  ```ts title="modern.config.ts"
73
73
  export default defineConfig({
@@ -85,6 +85,6 @@ export default defineConfig({
85
85
  ```
86
86
 
87
87
  :::note
88
- This configuration takes effect in both the production environment and the development environment, and can set different response headers according to the NODE_ENV. But if you only need to set response headers in the development environment, `tools.devServer.headers` is recommended.
88
+ This configuration takes effect in both the production and development environments, and different response headers can be set according to the NODE_ENV to distinguish between environments. However, if you only need to set response headers in the development environment, it is recommended to use `tools.devServer.headers`.
89
89
 
90
90
  :::
@@ -7,10 +7,10 @@ sidebar_label: ssrByEntries
7
7
  - **Type:** `Object`
8
8
  - **Default:** `undefined`
9
9
 
10
- Set the ssr option according to the entry. The attributes in the option are the same as [ssr](./ssr.mdx). The specified value will be replaced and merged with the content of the ssr attribute. For example:
10
+ Set SSR options by entry, and the properties inside the option are the same as [ssr](./ssr.mdx). The specified value will be replaced and merged with the content of the SSR attribute, for example:
11
11
 
12
12
  :::info
13
- The "entry name" defaults to the directory name. In a few cases, when the entry is customized by `source.entries`, the entry name `source.entries` the `key` of the object.
13
+ The "entry name" defaults to the directory name. In a few cases, when defining an entry through `source.entries`, the entry name is the `key` of the `source.entries` object.
14
14
 
15
15
  :::
16
16
 
@@ -19,11 +19,11 @@ export default defineConfig({
19
19
  server: {
20
20
  ssr: true,
21
21
  ssrByEntries: {
22
- // page-a does not enable ssr
22
+ // page-a does not enable SSR
23
23
  'page-a': false,
24
24
  },
25
25
  },
26
26
  });
27
27
  ```
28
28
 
29
- As configured above, the project has ssr enabled as a whole, but the ssr rendering capability is turned off for the entry `page-a`.
29
+ In the above configuration, the project enables SSR as a whole, but the SSR rendering ability is disabled for the `page-a` entry.
@@ -11,7 +11,7 @@ Enalbe SSR configuration.
11
11
 
12
12
  ### Boolean Type
13
13
 
14
- When the value type is `boolean`, it indicates whether to enable SSR deployment mode, and `false` is not enabled by default.
14
+ When the value type is `boolean`, it indicates whether to enable SSR deployment mode. The default is `false` to disable it.
15
15
 
16
16
  ```ts title="modern.config.ts"
17
17
  export default defineConfig({
@@ -23,11 +23,11 @@ export default defineConfig({
23
23
 
24
24
  ### Object Type
25
25
 
26
- When the value type is `Object`, The following properties can be configured:
26
+ When the value type is `Object`, the following properties can be configured:
27
27
 
28
- - `mode`: `string = 'string'`, use `renderToString` rendering default. onfigure 'stream' to enable streaming rendering.
29
- - `forceCSR`: `boolean = false`, forced CSR rendering is disable by default. When configured as `true`, add `?csr=true` in URL to force CSR.
30
- - `inlineScript`:`boolean = true`, by default SSR data will be injected into HTML as inline scripts and directly assigned to global variables. Configure as `false` to inject JSON instead of directly assigning.
28
+ - `mode`: `string = 'string'`, which defaults to using `renderToString` for rendering. Configure `stream` to enable streaming rendering.
29
+ - `forceCSR`: `boolean = false`, which is off by default for forcing CSR rendering. Configure `true` to force CSR by adding `?csr=true` 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.
31
31
 
32
32
  ```ts title="modern.config.ts"
33
33
  export default defineConfig({
@@ -8,14 +8,10 @@ sidebar_position: 1
8
8
  - **Type:** `'babel-jest' | 'ts-jest'`
9
9
  - **Default:** `babel-jest`
10
10
 
11
- :::caution Caution
12
- First you need to enable the "Unit Test" function using [new](/apis/app/commands#modern-new) command.
11
+ First need to run `new` command to enable [Unit Test / Integration Test] features.
13
12
 
14
- :::
15
-
16
- Configure the compiler for source code when executing tests: [babel-jest](https://www.npmjs.com/package/babel-jest) or [ts-jest](https://github.com/kulshekhar/ts-jest). `babel-jest` is used by default.
17
-
18
- :::info Additional information
19
- `Babel-jest` can also compile TS files, but there is no type error. If you need to check the TS type when running tests, then use `ts-jest`.
13
+ Configure the compilation tool used during test execution. By default, `babel-jest` is used. You can configure it to use either [babel-jest](https://www.npmjs.com/package/babel-jest) or [ts-jest](https://github.com/kulshekhar/ts-jest).
20
14
 
15
+ :::info Additional
16
+ `babel-jest` can compile TypeScript files but does not perform type checking. If you want to perform type checking on your TypeScript files while running test cases, you can use `ts-jest`.
21
17
  :::
@@ -12,7 +12,7 @@ The compile configuration can be configured in two places:
12
12
  - `package.json` file
13
13
 
14
14
  :::info
15
- Configurations in both package.json and modern.config.ts file are not supported for the same configuration. Configuration in modern.config.ts is recommended.
15
+ Configurations in both `package.json` and `modern.config.ts` file are not supported for the same configuration. Configuration in `modern.config.ts` is recommended.
16
16
  :::
17
17
 
18
18
  Server runtime configuration can be configured in the `modern.server-runtime.config.(ts|js|mjs)` file in the root path.
@@ -54,7 +54,7 @@ When using Rspack as the bundler, due to some differences in configuration types
54
54
 
55
55
  ### modern.config.js
56
56
 
57
- If you are developing a non-TypeScript project, you can use the configuration file in .js format:
57
+ If you are developing a non-TypeScript project, you can use the configuration file in `.js` format:
58
58
 
59
59
  ```js title="modern.config.js"
60
60
  export default {
@@ -66,7 +66,7 @@ export default {
66
66
  };
67
67
  ```
68
68
 
69
- You can also dynamically set it with `process.env.NODE _ENV`:
69
+ You can also configure depending on your environment with `process.env.NODE_ENV`:
70
70
 
71
71
  ```js title="modern.config.js"
72
72
  export default {
@@ -122,7 +122,7 @@ export default defineConfig(async ({ env, command }) => {
122
122
 
123
123
  You can specify the name of the configuration file using the `--config` option.
124
124
 
125
- For example, if you need to use the `modern.prod.config.js` file when running build, you can add the following scripts to `package.json`:
125
+ For example, if you need to use the `modern.prod.config.js` file when running `build`, you can add the following scripts to `package.json`:
126
126
 
127
127
  ```json title="package.json"
128
128
  {
@@ -155,7 +155,7 @@ In addition to configuration files, configuration options can also be set the `m
155
155
  }
156
156
  ```
157
157
 
158
- Due to the limitation of the JSON file format, only simple types such as numbers, strings, boolean values, arrays, etc. can be defined in `package.json`. When we need to set the value of the function type, it is recommended to set it in the Modern.js configuration file.
158
+ Due to the limitation of the JSON file format, only simple types such as numbers, strings, boolean values, arrays, etc. can be defined in `package.json`. When we need to set the value of the function type, it is recommended to do so in the Modern.js configuration file.
159
159
 
160
160
  ### Note
161
161
 
@@ -2,13 +2,12 @@
2
2
  title: Code Split
3
3
  sidebar_position: 6
4
4
  ---
5
- # Code Split
5
+ # Code Splitting
6
6
 
7
- Code Split is a common way to optimizing front-end resource loading. This doc will introduce three methods supported by Modern.js:
7
+ Code splitting is a common way to optimize frontend resource loading. This article will introduce the three types of code splitting supported by Modern.js:
8
8
 
9
9
  :::info
10
- When you use Modern.js [Conventional routing](/guides/basic-features/routes#conventional-routing), by default it will do code splitting based on routing components, wrapping `Suspense` components, no need to do code splitting by yourself.
11
-
10
+ When using Modern.js [Conventional routing](/guides/basic-features/routes#conventional-routing). By default, code splitting is done according to the routing component, so you don't need to do it yourself.
12
11
  :::
13
12
 
14
13
  - `import`
@@ -17,7 +16,7 @@ When you use Modern.js [Conventional routing](/guides/basic-features/routes#conv
17
16
 
18
17
  ## import
19
18
 
20
- use dynamic `import()`, `import` The JS modules pass to this API will be packaged into a separate JS file as a new packaging entry, for example:
19
+ use dynamic `import()`, the JS modules pass to this API will be packaged as a separate JS file, for example:
21
20
 
22
21
  ```ts
23
22
  import('./math').then(math => {
@@ -25,15 +24,14 @@ import('./math').then(math => {
25
24
  });
26
25
  ```
27
26
 
28
- The JS modules corresponding to the './math' path will be packaged in a separate JS file.
29
-
30
27
  ## React.lazy
31
28
 
32
29
  The officially way provides by React to split component code.
33
30
 
34
31
  :::caution
35
- SSR is not supported in React 17 and below, and it is recommended that SSR applications for React 17 use loadable.
32
+ `React.lazy` is typically used in together with `<Suspense>`, hence it is only available in CSR or React 18 Streaming SSR.
36
33
 
34
+ For projects that use Traditional SSR(renderToString), `React.lazy` is not supported. Please use the Loadable API instead.
37
35
  :::
38
36
 
39
37
  ```ts
@@ -56,11 +54,11 @@ function MyComponent() {
56
54
  }
57
55
  ```
58
56
 
59
- For detail, see [React lazy](https://reactjs.org/docs/code-splitting.html#reactlazy).
57
+ For details, see [React lazy](https://react.dev/reference/react/lazy).
60
58
 
61
- ## loadable
59
+ ## Loadable
62
60
 
63
- use `loadable` API, for example:
61
+ In Modern.js, you can use the Loadable API, which is exported from `@modern-js/runtime/loadable`. Here's an example:
64
62
 
65
63
  ```ts
66
64
  import loadable from '@modern-js/runtime/loadable';
@@ -72,9 +70,12 @@ function MyComponent() {
72
70
  }
73
71
  ```
74
72
 
75
- For detail, see [loadable API](/apis/app/runtime/utility/loadable).
73
+ With the out-of-the-box support of `loadable` in SSR by Modern.js, you no longer need to add Babel plugins or inject scripts into HTML during SSR.
76
74
 
77
- :::info
78
- SSR is supported out of the box by `loadable`.
75
+ However, it's important to note that any Loadable API in SSR does not support the use of `<Suspense>`.
79
76
 
77
+ :::info
78
+ If you want to use `<Suspense>` in CSR projects with React 17 and below, you can substitute `React.lazy` with `loadable.lazy`.
80
79
  :::
80
+
81
+ For details, see [Loadable API](/apis/app/runtime/utility/loadable).
@@ -6,9 +6,9 @@ sidebar_position: 5
6
6
 
7
7
  ## Browserslist Configuration
8
8
 
9
- Modern.js supports setting the browserslist for your web applications. You can set the [Browserslist](https://browsersl.ist/) in the `.browserslistrc` file.
9
+ Modern.js supports setting the browserslist for your web applications. You can set the value of [Browserslist](https://browsersl.ist/) in the `.browserslistrc` file.
10
10
 
11
- When you create a new Modern.js project, it includes a `.browserslistrc` configuration by default, which means that JavaScript code will be compiled to ES6.
11
+ When you create a new Modern.js project, it will includes a `.browserslistrc` configuration by default, which means that the JavaScript code will be compiled to ES6.
12
12
 
13
13
  ```yaml title=".browserslistrc"
14
14
  chrome >= 51
@@ -22,32 +22,11 @@ ios_saf >= 10
22
22
  Please refer to [Modern.js Builder - Browserslist](https://modernjs.dev/builder/en/guide/advanced/browserslist) for more information.
23
23
  :::
24
24
 
25
- ## Browserslist
26
-
27
- Modern.js supports the `browserslist` field in the `package.json` file, or a `.browserslistrc` file to specify the target browser range covered by the project.
28
-
29
- This value is used by ['@babel/preset-env'] (https://babeljs.io/docs/en/babel-preset-env) and ['autoprefixer'] (https://github.com/postcss/autoprefixer) to determine the JavaScript syntax features to be converted and the CSS browser prefix to be added.
30
-
31
- The default value in Modern.js as follow:
32
-
33
- ```js
34
- ['> 0.01%', 'not dead', 'not op_mini all'];
35
- ```
36
-
37
- You can learn how to customize the browserslist [here](https://github.com/browserslist/browserslist).
38
-
39
- See Modern.js Builder docs to learn more [Browserslist](https://modernjs.dev/builder/en/guide/advanced/browserslist.html) info.
40
-
41
- :::note
42
- Modern.js also supports configuring [output.override Browserslist](/configure/app/output/override-browserslist) to override the default browserslist value.
43
-
44
- :::
45
-
46
25
  ## Polyfill
47
26
 
48
27
  ### Polyfill At Compile
49
28
 
50
- Modern.js inject the Polyfill code via [core-js] (https://github.com/zloirock/core-js) at compile time by default.
29
+ Modern.js defaults to importing corresponding polyfill code from [core-js] (https://github.com/zloirock/core-js) during compilation.
51
30
 
52
31
  By default, the required Polyfill code will be introduced according to the settings of the Browserslist, so there is no need to worry about the Polyfill problem of the project source code and third-party dependencies, but because it contains some Polyfill code that is not used, the final bundle size may be increased.
53
32
 
@@ -80,7 +80,6 @@ For example, if you are using pnpm, you can update the Rspack version with `over
80
80
  "overrides": {
81
81
  "@rspack/core": "nightly",
82
82
  "@rspack/dev-client": "nightly",
83
- "@rspack/dev-middleware": "nightly",
84
83
  "@rspack/plugin-html": "nightly"
85
84
  }
86
85
  }
@@ -75,7 +75,7 @@ Warning: Expected server HTML to contain a matching <div> in <div>.
75
75
  This is caused by the inconsistency between the rendering result and the SSR rendering result when React executes the hydrate logic on the client side. Although the page performs normally, in complex applications, it is likely to cause problems such as DOM hierarchy confusion and style confusion.
76
76
 
77
77
  :::info
78
- For hydrate logic, please refer to [here](https://reactjs.org/docs/react-dom.html#hydrate).
78
+ For hydrate logic, please refer to [here](https://react.dev/reference/react-dom/hydrate).
79
79
 
80
80
  :::
81
81
 
@@ -455,7 +455,7 @@ export default Page;
455
455
  ```
456
456
 
457
457
  `Await` needs to be wrapped inside the `Suspense` component. The `resolve` of `Await` passes in the data acquired asynchronously by the Data Loader. When the data acquisition is completed,
458
- the obtained data is rendered through the [Render Props](https://reactjs.org/docs/render-props.html) mode. When the data acquisition is in pending status, the
458
+ the obtained data is rendered through the [Render Props](https://react.dev/reference/react/cloneElement#passing-data-with-a-render-prop) mode. When the data acquisition is in pending status, the
459
459
  content set by the `fallback` property of the `Suspense` component will display.
460
460
 
461
461
 
@@ -6,16 +6,16 @@ title: Testing
6
6
 
7
7
  Modern.js integrates the testing capabilities of [Jest](https://jestjs.io/) by default.
8
8
 
9
- First need to execute `pnpm run new` enable [unit test/integration test] features:
9
+ First need to execute `pnpm run new` to enable [unit test/integration test] features:
10
10
 
11
- ```
11
+ ```bash
12
12
  ? Please select the operation you want: Enable features
13
13
  ? Please select the feature name: Enable Unit Test / Integration Test
14
14
  ```
15
15
 
16
- After executing the above command, the `"test": "modern test"` command will be automatically generated in package.json.
16
+ After executing the above command, the `"test": "modern test"` command will be added in `package.json` automatically.
17
17
 
18
- register plugin in `modern.config.ts`:
18
+ After registering the `@modern-js/plugin-testing` plugin in `modern.config.ts`, you can use the testing features:
19
19
 
20
20
  ```ts title="modern.config.ts"
21
21
  import testPlugin from '@modern-js/plugin-testing';
@@ -35,12 +35,13 @@ If you need to customize the test directory, you can configure it with [tools.je
35
35
 
36
36
  Modern.js test support [testing-library](https://testing-library.com/docs/). API can be imported from `@modern-js/runtime/testing`.
37
37
 
38
- ```
38
+ ```ts
39
39
  import { render, screen } from '@modern-js/runtime/testing';
40
40
  ```
41
41
 
42
- Other Modern.js supported testing APIs can be found [here](/apis/app/runtime/testing/cleanup).
42
+ Other testing APIs supported by Modern.js can be referred to [here](/apis/app/runtime/testing/cleanup).
43
43
 
44
44
  ## transform
45
45
 
46
- Modern.js tests use [babel-jest](https://www.npmjs.com/package/babel-jest) for source code compilation by default. If you need to use [ts-jest](https://github.com/kulshekhar/ts-jest), you can configure it through [testing.transform](/configure/app/testing/transformer).
46
+ By default, Modern.js testing uses [babel-jest](https://www.npmjs.com/package/babel-jest) for source code compilation. If you need to use [ts-jest](https://github.com/kulshekhar/ts-jest), you can configure it through [testing.transform](/configure/app/testing/transformer).
47
+
@@ -0,0 +1,44 @@
1
+ ---
2
+ sidebar_position: 20
3
+ ---
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
+ ## Enable Storybook debugging
16
+
17
+ The Modern.js framework integrates the Builder's Node Polyfill plugin by default.
18
+
19
+ If you want to debug the component, you can enable Storybook debugging through `pnpm run new`.
20
+
21
+ ```bash
22
+ $ npx modern new
23
+ ? Please select the operation you want: Enable features
24
+ ? Please select the feature name: Enable Visual Testing (Storybook)
25
+ ```
26
+
27
+ 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.
28
+
29
+ ```ts title="modern.config.ts"
30
+ import appTools, { defineConfig } from '@modern-js/app-tools';
31
+ import storybookPlugin from '@modern-js/plugin-storybook';
32
+
33
+ export default defineConfig({
34
+ plugins: [appTools(), storybookPlugin()],
35
+ });
36
+ ```
37
+
38
+ ## Debugging code
39
+
40
+ 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.
41
+
42
+ ## Configure Storybook
43
+
44
+ In Modern.js, Storybook configuration files can be added to the [`config/storybook`](/apis/app/hooks/config/storybook.html) directory of the project.
@@ -4,15 +4,15 @@ sidebar_position: 3
4
4
  ---
5
5
  # Custom Web Server
6
6
 
7
- As a client side-centric development framework, Modern.js has weak customization capabilities on the server side. In some development scenarios, special server level logic needs to be customized, such as user authentication, request preprocessing, and adding page rendering skeletons.
7
+ As a client-centric development framework, Modern.js has limited customization capabilities on the server side. However, in some development scenarios, special server-level logic needs to be customized, such as user authentication, request preprocessing, and adding page rendering skeletons.
8
8
 
9
- Some developers may be wondering, Modern.js already provides [BFF](/guides/advanced-features/bff/function.html), why do you need **Custom Web Server**.
9
+ Some developers may be wondering, Modern.js already provides [BFF](/guides/advanced-features/bff/function.html), why you need **Custom Web Server**.
10
10
 
11
- Because by default, page routing does not go through BFF, it has no way to provide server-side custom logic for page access. The reason for this design is that we do not want the service that controls the page to be bound to the BFF service, so as to avoid the BFF framework restricting how the page is deployed.
11
+ The reason is that by default, page routing does not go through BFF, it has no way to provide server-side custom logic for page access. The reason for this design is that we do not want the service that controls the page to be bound to the BFF service, this is to avoid the BFF framework restricting how the page is deployed.
12
12
 
13
- For example, hosting pages separately from BFF, deploying page services to non-Node environments, or customizing for deployment platforms, etc.
13
+ For example, hosting pages separately from BFF, deploying page services to non-Node environments, customizing for deployment platforms, etc.
14
14
 
15
- For the above reasons, Modern.js provides three ways that projects can customize server level capabilities progressively according to their needs.
15
+ For the above reasons, Modern.js provides three ways that projects can customize server-level capabilities progressively according to their needs.
16
16
 
17
17
  :::warning
18
18
  The three extension methods cannot work at the same time, and developers need to choose the appropriate method according to the scenario.
@@ -20,11 +20,11 @@ The three extension methods cannot work at the same time, and developers need to
20
20
 
21
21
  ## Extending Web Server with API
22
22
 
23
- The first way is to customize the server level at a specific life cycle through the server level runtime API provided by Modern.js. The purpose of providing this way is that in some cases, developers do not need to control the full Web Server, but only need to add server level logic.
23
+ The first way is to customize the server-side at a specific lifecycle through the server-side runtime API provided by Modern.js. The purpose of providing this way is that in some cases, developers do not need to control the full Web Server, but only need to add server-level logic.
24
24
 
25
- Because the full web server cannot be controlled this way, and the extension logic **only takes effect when the page is requested**. Therefore, it is relatively simple to apply to server level logic, and you do not want to create additional BFFs or BFFs and pages without common server level logic scenarios.
25
+ Because the full web server cannot be controlled this way, and the extension logic **only takes effect when the page is requested**. Therefore, it is relatively simple to apply server-level logic, and you do not want to create additional BFFs or BFFs and pages without common server-level logic scenarios.
26
26
 
27
- You can execute the'pnpm run new 'command in the project root directory to enable the "Custom Web Serve" function:
27
+ You can run the'pnpm run new 'command in the project root directory to enable the "Custom Web Serve" function:
28
28
 
29
29
  ```bash
30
30
  ? Please select the operation you want: Create Element
@@ -47,7 +47,7 @@ After the function is turned on, the `server/index.ts` file will be automaticall
47
47
 
48
48
  The Hook provided by Modern.js is used to control the built-in logic in the Web Server, and all page requests go through the Hook.
49
49
 
50
- There are currently two Hooks provided, namely `AfterMatch` and `AfterRender`, which can be used to modify the rendering results. It can be written in `server/index.ts` like this:
50
+ Currently, two Hooks are provided: `AfterMatch` and `AfterRender`, which can be used to modify the rendering results. It can be written in `server/index.ts` as follows:
51
51
 
52
52
  ```ts
53
53
  import type { AfterMatchHook, AfterRenderHook } from '@modern-js/runtime/server';
@@ -61,11 +61,11 @@ export const afterRender: AfterRenderHook = (ctx, next) => {
61
61
  }
62
62
  ```
63
63
 
64
- Projects should have the following best practices when using Hook:
64
+ Projects should follow these best practices when using Hook:
65
65
 
66
- 1. Permission verification in afterMatch.
66
+ 1. Authentication in afterMatch.
67
67
  2. Do Rewrite and Redirect in afterMatch.
68
- 3. Do HTML content injection in afterRender.
68
+ 3. Inject HTML content in afterRender.
69
69
 
70
70
  :::note
71
71
  For more detail, see [Hook](/apis/app/runtime/web-server/hook).
@@ -91,10 +91,10 @@ export const middleware: Middlewre = (context, next) => {
91
91
  For more detail, see [Middleware] (/apis/app/runtime/web-server/middleware).
92
92
  :::
93
93
 
94
- Projects should have the following best practices when using Middleware:
94
+ Projects should follow these best practices when using Middleware:
95
95
 
96
96
  1. In Middleware, you can directly operate origin request and response objects, do event tracking, and inject Node services (databases, Redis, etc.) that may be used for SSR rendering.
97
- 2. Marking and crawler optimization can be done in Middleware.
97
+ 2. Operations such as marking and crawler optimization can be done in Middleware.
98
98
  3. In Middleware, you can ignore the default rendering and customize the rendering process.
99
99
 
100
100
  **In general, in CSR projects, using Hook can basically meet all the needs of simple scenarios. In SSR projects, Middleware can be used for more complex Node extensions.**
@@ -103,9 +103,9 @@ Projects should have the following best practices when using Middleware:
103
103
 
104
104
  The second way is to use BFF to Managed page rendering. In this way, all requests will first hit the BFF service.
105
105
 
106
- This method can uniformly control the server level logic of all requests through BFF. Therefore, it is suitable for scenarios where the server level logic is complex, and BFF and pages need common server level logic. But it still relies on the Web Server of Modern.js as a whole, and cannot run the logic on existing services.
106
+ This method can uniformly control the server-level logic of all requests through BFF. Therefore, it is suitable for scenarios where the server-level logic is complex, and BFF and pages need common server-level logic. But it still relies on the Web Server of Modern.js as a whole, and cannot run the logic on existing services.
107
107
 
108
- To use this method, we need to first enable the "BFF" function through `pnpm new`. Then add [`bff.enableHandleWeb`](/configure/app/bff/enable-handle-web.html) configuration in the configuration file:
108
+ To use this method, we first need to enable the "BFF" function through `pnpm new`. Then add [`bff.enableHandleWeb`](/configure/app/bff/enable-handle-web.html) configuration in the configuration file:
109
109
 
110
110
  ```ts
111
111
  export default defineConfig({