@modern-js/main-doc 2.51.0 → 2.53.0

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.
Files changed (68) hide show
  1. package/docs/en/apis/app/runtime/web-server/unstable_middleware.mdx +30 -4
  2. package/docs/en/guides/advanced-features/web-server.mdx +4 -2
  3. package/docs/en/guides/basic-features/data/data-fetch.mdx +28 -0
  4. package/docs/en/guides/basic-features/deploy.mdx +143 -33
  5. package/docs/en/guides/basic-features/routes.mdx +2 -2
  6. package/docs/en/guides/get-started/tech-stack.mdx +0 -6
  7. package/docs/en/guides/topic-detail/framework-plugin/plugin-api.mdx +1 -1
  8. package/docs/en/guides/topic-detail/generator/create/option.md +0 -5
  9. package/docs/en/guides/topic-detail/generator/create/use.mdx +1 -10
  10. package/docs/en/guides/topic-detail/generator/new/config.md +0 -29
  11. package/docs/en/guides/topic-detail/generator/new/use.md +0 -20
  12. package/docs/zh/apis/app/runtime/web-server/unstable_middleware.mdx +30 -4
  13. package/docs/zh/guides/advanced-features/web-server.mdx +1 -1
  14. package/docs/zh/guides/basic-features/data/data-fetch.mdx +27 -2
  15. package/docs/zh/guides/basic-features/deploy.mdx +140 -36
  16. package/docs/zh/guides/basic-features/routes.mdx +2 -2
  17. package/docs/zh/guides/get-started/tech-stack.mdx +0 -6
  18. package/docs/zh/guides/topic-detail/framework-plugin/plugin-api.mdx +1 -1
  19. package/docs/zh/guides/topic-detail/generator/create/option.md +0 -5
  20. package/docs/zh/guides/topic-detail/generator/create/use.mdx +1 -10
  21. package/docs/zh/guides/topic-detail/generator/new/config.md +0 -31
  22. package/docs/zh/guides/topic-detail/generator/new/use.md +0 -20
  23. package/package.json +5 -5
  24. package/docs/en/apis/app/runtime/testing/_category_.json +0 -4
  25. package/docs/en/apis/app/runtime/testing/act.mdx +0 -35
  26. package/docs/en/apis/app/runtime/testing/cleanup.mdx +0 -40
  27. package/docs/en/apis/app/runtime/testing/render.mdx +0 -71
  28. package/docs/en/apis/app/runtime/testing/renderApp.mdx +0 -34
  29. package/docs/en/configure/app/testing/_category_.json +0 -4
  30. package/docs/en/configure/app/testing/transformer.mdx +0 -17
  31. package/docs/en/configure/app/tools/jest.mdx +0 -40
  32. package/docs/en/guides/advanced-features/testing.mdx +0 -47
  33. package/docs/en/guides/topic-detail/changesets/_category_.json +0 -4
  34. package/docs/en/guides/topic-detail/changesets/add.mdx +0 -125
  35. package/docs/en/guides/topic-detail/changesets/changelog.mdx +0 -238
  36. package/docs/en/guides/topic-detail/changesets/commit.mdx +0 -269
  37. package/docs/en/guides/topic-detail/changesets/config.mdx +0 -147
  38. package/docs/en/guides/topic-detail/changesets/github.mdx +0 -175
  39. package/docs/en/guides/topic-detail/changesets/introduce.mdx +0 -56
  40. package/docs/en/guides/topic-detail/changesets/release-note.mdx +0 -274
  41. package/docs/en/guides/topic-detail/changesets/release-pre.mdx +0 -49
  42. package/docs/en/guides/topic-detail/changesets/release.mdx +0 -229
  43. package/docs/en/guides/topic-detail/model/test-model.mdx +0 -45
  44. package/docs/zh/apis/app/runtime/testing/_category_.json +0 -4
  45. package/docs/zh/apis/app/runtime/testing/act.mdx +0 -35
  46. package/docs/zh/apis/app/runtime/testing/cleanup.mdx +0 -40
  47. package/docs/zh/apis/app/runtime/testing/render.mdx +0 -71
  48. package/docs/zh/apis/app/runtime/testing/renderApp.mdx +0 -32
  49. package/docs/zh/configure/app/testing/_category_.json +0 -4
  50. package/docs/zh/configure/app/testing/transformer.mdx +0 -19
  51. package/docs/zh/configure/app/tools/jest.mdx +0 -40
  52. package/docs/zh/guides/advanced-features/testing.mdx +0 -47
  53. package/docs/zh/guides/topic-detail/changesets/_category_.json +0 -4
  54. package/docs/zh/guides/topic-detail/changesets/add.mdx +0 -126
  55. package/docs/zh/guides/topic-detail/changesets/changelog.mdx +0 -238
  56. package/docs/zh/guides/topic-detail/changesets/commit.mdx +0 -269
  57. package/docs/zh/guides/topic-detail/changesets/config.mdx +0 -147
  58. package/docs/zh/guides/topic-detail/changesets/github.mdx +0 -175
  59. package/docs/zh/guides/topic-detail/changesets/introduce.mdx +0 -56
  60. package/docs/zh/guides/topic-detail/changesets/release-note.mdx +0 -274
  61. package/docs/zh/guides/topic-detail/changesets/release-pre.mdx +0 -50
  62. package/docs/zh/guides/topic-detail/changesets/release.mdx +0 -231
  63. package/docs/zh/guides/topic-detail/model/test-model.mdx +0 -45
  64. package/docs/zh/guides/topic-detail/monorepo/_category_.json +0 -4
  65. package/docs/zh/guides/topic-detail/monorepo/create-sub-project.mdx +0 -53
  66. package/docs/zh/guides/topic-detail/monorepo/intro.mdx +0 -14
  67. package/docs/zh/guides/topic-detail/monorepo/publish.mdx +0 -69
  68. package/docs/zh/guides/topic-detail/monorepo/sub-project-interface.mdx +0 -143
@@ -2,18 +2,21 @@
2
2
  sidebar_position: 15
3
3
  ---
4
4
 
5
- # 部署
5
+ # 部署应用
6
6
 
7
- 目前 Modern.js 支持在 node.js 环境下运行,你可以自行托管,同时,Modern.js 官方支持在 Netlify 平台上部署。
7
+ 目前,Modern.js 提供了两种部署方式:
8
+
9
+ - 你可以将应用自行托管在包含 Node.js 环境的容器中,这为应用提供了部署的灵活性。
10
+ - 你也可以通过平台部署应用,目前 Modern.js 官方支持了 [Netlify](https://www.netlify.com/) 和 [Vercel](https://vercel.com/) 平台。
8
11
 
9
12
  :::info
10
- 当前仅支持在 node.js 环境运行,对其他运行时环境的支持将在后续版本中提供。
13
+ 目前 Modern.js 仅支持在 Node.js 环境中运行,未来将提供更多运行时环境的支持。
11
14
  :::
12
15
 
13
16
 
14
- ## 构建产物的命令
17
+ ## 构建部署产物
15
18
 
16
- 执行 `modern deploy` 命令将自动构建适用于生产环境的输出文件。此过程包括优化输出文件及其依赖,并检测当前部署平台,自动生成可以在该平台运行的产物。
19
+ 执行 `modern deploy` 命令将自动输出部署产物。此过程包括优化 Bundler 构建产物及产物依赖,检测当前部署平台,并自动生成可以在该平台运行的产物。
17
20
  如果你希望在本地生成并测试特定部署平台的产物,可以通过设置环境变量来指定平台:
18
21
 
19
22
  ```bash
@@ -29,24 +32,26 @@ MODERNJS_DEPLOY=netlify npx modern deploy
29
32
 
30
33
  ### 单仓库项目
31
34
 
32
- 默认情况下,当未检测到 Modern.js 支持的部署平台时,Modern.js 会输出可以在 Node.js 环境下运行的构建产物。
35
+ 默认情况下,如果未检测到 Modern.js 支持的部署平台,Modern.js 将生成可以在 Node.js 环境下运行的部署产物。
36
+
37
+ 你可以使用以下命令构建项目:
33
38
 
34
- 使用以下命令构建项目:
35
39
  ```bash
36
40
  npx modern deploy
37
41
  ```
38
42
 
39
- 当执行 `modern deploy` 命令时,Modern.js 会产出可运行的生产环境产物,并输出以下内容:
43
+ 当执行 `modern deploy` 命令时,Modern.js 将生成可执行的部署产物,并在控制台输出以下内容:
40
44
 
41
45
  ```bash
42
46
  Static directory: `.output/static`
43
47
  You can preview this build by `node .output/index`
44
48
  ```
45
49
 
46
- 此时,你可以通过 `node .output/index` 运行整个 server,在 `.output/static` 目录下是页面所需的静态资源,你可以将这些静态资源自行上传至 CDN
50
+ 现在,你可以通过执行 `node .output/index` 命令来运行服务器。在 `.output/static` 目录中,存放了页面运行所需的静态资源,你可以选择将这些资源上传到 CDN 以提高访问速度。
47
51
 
48
52
  :::info
49
- 默认情况下,运行 Modern.js Server 时会监听 8080 端口,如果你想修改监听的端口,可以指定 `PORT` 环境变量:
53
+ 默认情况下,运行 Modern.js 服务器时会监听 8080 端口,如果你想修改监听的端口,可以指定 `PORT` 环境变量:
54
+
50
55
  ```
51
56
  PORT=3000 node .output/index
52
57
  ```
@@ -55,36 +60,35 @@ PORT=3000 node .output/index
55
60
 
56
61
  ### Monorepo
57
62
 
58
- 对于 Monorepo 项目,除了需要构建我们当前的项目外,还需要构建当前项目的依赖的其他仓库。
63
+ 对于 Monorepo 项目,除了需要构建当前的项目外,还需要构建当前项目依赖的仓库中其他子项目。
59
64
 
60
- 假设当前项目的 `package.json` 中的 name 为 `app`,以 pnpm 作为 monorepo 管理工具为例,你可以在当前项目的 `package.json` 添加以下命令用于构建当前项目的产物:
65
+ 假设当前项目的 `package.json` 中的 name 为 `app`,以 pnpm 作为 Monorepo 管理工具为例,你可以在项目 `package.json` 中添加以下命令用于构建:
61
66
 
62
67
  ```json title="app/package.json"
63
68
  {
64
69
  "scripts": {
65
- "deploy": "modern deploy",
66
- "deploy:app": "pnpm --filter 'app^...' run build && pnpm --filter=app run deploy",
70
+ "build:packages": "pnpm --filter 'app^...' run build",
71
+ "deploy": "pnpm run build:packages && modern deploy",
67
72
  }
68
73
  }
69
74
  ```
70
75
 
71
- 如果你使用 rush 管理仓库,可以在 `package.json` 中添加以下命令:
76
+ 如果你使用 rush 作为 Monorepo 管理工具,可以在 `package.json` 中添加以下命令:
72
77
 
73
78
  ```json
74
79
  {
75
80
  "scripts": {
76
- "deploy": "modern deploy",
77
- "deploy:app": "rush rebuild --to-except app && rushx deploy",
81
+ "build:packages": "rush rebuild --to-except app",
82
+ "deploy": "rushx build:packages && modern deploy",
78
83
  }
79
84
  }
80
85
  ```
81
86
 
82
- 当构建完成后,Modern.js 会将项目中所有的依赖生成在 `.output/node_modules` 目录下。同样的,你可以使用 `node .output/index` 运行整个 Server。
87
+ 构建完成后,框架会将项目中所有的依赖生成在 `.output/node_modules` 目录下。你同样可以使用 `node .output/index` 运行 Modern.js 服务器。
83
88
 
84
89
  ## Netlify
85
90
 
86
- Netlify 是一个流行的 web 开发平台,专为构建、发布和维护现代 web 项目而设计,在 Netlify 上部署,主要需要配置 `netlify.toml` 文件,
87
- 根据你的项目复杂度,可以渐进配置。
91
+ Netlify 是一个流行的 Web 开发平台,专为构建、发布和维护现代 Web 项目而设计。在 Netlify 上部署,通常需要配置 `netlify.toml` 文件,你可以根据项目复杂度,渐进地配置该文件。
88
92
 
89
93
  ### 纯前端项目
90
94
 
@@ -92,30 +96,29 @@ Netlify 是一个流行的 web 开发平台,专为构建、发布和维护现
92
96
 
93
97
  ```bash
94
98
  ./
95
- ├── src/
99
+ ├── src
96
100
  ├── modern.config.ts
97
101
  ├── netlify.toml
98
- ├── package.json
102
+ └── package.json
99
103
  ```
100
104
 
101
105
  在 `netlify.toml` 中添加以下内容:
102
106
  ```toml
103
107
  [build]
104
108
  publish = "dist"
105
- command = "npm run deploy"
109
+ command = "modern deploy"
106
110
  ```
107
111
 
108
112
  在 Netlify 平台上添加项目,部署即可。
109
113
 
110
114
  ### 全栈项目
111
115
 
112
- 全栈项目是指使用了 自定义 ServerSSRBFF 的项目,这些项目需要部署在 Netlify Functions 上。基于上述的 `netlify.toml` 文件,
113
- 添加以下配置:
116
+ 全栈项目是指使用了自定义 Web ServerSSRBFF 的项目,这些项目需要部署在 **Netlify Functions** 上。你需要基于上述的 `netlify.toml` 文件,添加以下配置:
114
117
 
115
118
  ```toml title="netlify.toml"
116
119
  [build]
117
120
  publish = "dist"
118
- command = "npm run deploy"
121
+ command = "modern deploy"
119
122
 
120
123
  [functions]
121
124
  directory = ".netlify/functions"
@@ -131,30 +134,36 @@ Netlify 是一个流行的 web 开发平台,专为构建、发布和维护现
131
134
 
132
135
  ### Monorepo 项目
133
136
 
134
- 对于 Monorepo 项目,除了需要构建我们当前的项目外,还需要构建当前项目的依赖的其他仓库。我们以一个 pnpm monorepo 仓库为例,
135
- Netlify 上对 Monorepo 项目进行部署。
137
+ :::info
138
+ 以下指南主要针对于全栈项目,对于纯 CSR 的项目,只需要按照[纯前端项目](#纯前端项目)部署即可。
139
+ :::
140
+
141
+ 对于 Monorepo 项目,除了需要构建当前的项目外,还需要构建当前项目依赖的仓库中其他子项目。这里以一个 pnpm Monorepo 仓库为例,在 Netlify 上对 Monorepo 项目进行部署。
136
142
 
137
- 假设我们有以下 Monorepo 仓库:
143
+ 假设 Monorepo 仓库目录结构如下:
138
144
 
139
145
  ```
140
- ./
141
- ├── packages/
142
- │ ├── app/
146
+ .
147
+ ├── packages
148
+ │ ├── app
143
149
  │ └── app-dep1
144
150
  ├── package.json
145
151
  ├── pnpm-lock.yaml
146
152
  └── pnpm-workspace.yaml
147
153
  ```
148
154
 
149
- 我们需要在 netlify 平台上配置 Base directory 为 `packages/app`:
155
+ 你需要在 Netlify 平台上配置 **Base directory** 为 `packages/app`:
150
156
 
151
157
  <img src="https://sf16-sg.tiktokcdn.com/obj/eden-sg/lmeh7nuptpfnuhd/netlify-monorepo-basedir.png?x-resource-account=public" />
152
158
 
153
159
  在 `packages/app/package.json` 中添加以下 script,在执行 `app` 仓库的部署命令之前,先执行 workspace 中其他仓库的构建:
154
160
 
155
161
  ```json
156
- "scripts": {
157
- "deploy:app": "pnpm --filter 'app^...' run build && pnpm --filter=app run deploy",
162
+ {
163
+ "scripts": {
164
+ "build:packages": "pnpm --filter 'app^...' run build",
165
+ "deploy": "pnpm run build:packages && modern deploy",
166
+ }
158
167
  }
159
168
  ```
160
169
 
@@ -163,7 +172,7 @@ Netlify 是一个流行的 web 开发平台,专为构建、发布和维护现
163
172
  ```toml
164
173
  [build]
165
174
  publish = "dist"
166
- command = "npm run deploy:app"
175
+ command = "npm run deploy"
167
176
 
168
177
  [functions]
169
178
  directory = ".netlify/functions"
@@ -173,5 +182,100 @@ Netlify 是一个流行的 web 开发平台,专为构建、发布和维护现
173
182
 
174
183
  提交你的代码,使用 Netlify 平台部署即可。
175
184
 
185
+ ## Vercel
186
+
187
+ Vercel 是一个面向现代 Web 应用的部署平台,它提供了丰富的功能,支持部署静态网站,服务端渲染应用等。在 Vercel 上部署,通常需要配置 `vercel.json` 文件,你可以根据项目复杂度,渐进地配置该文件。
188
+
189
+ ### 纯前端项目
190
+
191
+ 在当前项目的根目录添加 `vercel.json` 文件:
192
+ ```bash
193
+ ./
194
+ ├── src
195
+ ├── modern.config.ts
196
+ ├── vercel.json
197
+ └── package.json
198
+ ```
199
+
200
+ 在 `vercel.json` 中添加以下内容:
201
+ ```json title="vercel.json"
202
+ {
203
+ "buildCommand": "modern deploy",
204
+ "outputDirectory": ".vercel/output"
205
+ }
206
+ ```
207
+
208
+ 提交你的项目到 git,在 Vercel 平台上选择 Frmeworkwork Preset 为 `Other`,部署即可。
209
+
210
+ <img src="https://sf16-sg.tiktokcdn.com/obj/eden-sg/lmeh7nuptpfnuhd/vercel-framework-preset.png" />
211
+
212
+ ### 全栈项目
213
+
214
+ 全栈项目是指使用了自定义 Web Server、SSR、BFF 的项目,这些项目需要部署在 **Vercel Functions** 上。
215
+
216
+ 全栈项目除了按照[纯前端项目](#纯前端项目)的方式配置 `vercel.json` 外,有两点需要注意:
217
+
218
+ 1. 当前,Modern.js 还不支持在 Vercel 平台上部署 BFF 项目,我们将在后续的版本中支持。
219
+ 2. Vercel 平台部署时,默认 node 运行时为 `20.x`,部署全栈项目时建议选择 `18.x`,具体原因详见[Serverless Function contains invalid runtime error](https://vercel.com/guides/serverless-function-contains-invalid-runtime-error),你可以修改 `package.json` 指定版本:
220
+ ```json title="package.json"
221
+ "engines": {
222
+ "node": "18.x"
223
+ }
224
+ ```
225
+
226
+
227
+ ### Monorepo 项目
228
+
229
+ :::info
230
+ 以下指南主要针对于全栈项目,对于纯 CSR 的项目,只需要按照[纯前端项目](#纯前端项目-1)部署即可。
231
+ :::
232
+
233
+ 对于 Monorepo 项目,除了需要构建当前的项目外,还需要构建当前项目依赖的仓库中其他子项目。这里以一个 pnpm Monorepo 仓库为例,在 Vercel 上对 Monorepo 项目进行部署。
234
+
235
+ 假设 Monorepo 仓库目录结构如下:
236
+
237
+ ```
238
+ .
239
+ ├── packages
240
+ │ ├── app
241
+ │ └── app-dep1
242
+ ├── package.json
243
+ ├── pnpm-lock.yaml
244
+ └── pnpm-workspace.yaml
245
+ ```
246
+
247
+ 首先,你需要在 Vercel 平台上配置 **Root Directory** 为 `packages/app`:
248
+
249
+ <img src="https://sf16-sg.tiktokcdn.com/obj/eden-sg/lmeh7nuptpfnuhd/vercel-root-directory.png" />
250
+
251
+ 将 Node.js 运行时设置为 `18.x`:
252
+ ```json title="package.json"
253
+ "engines": {
254
+ "node": "18.x"
255
+ },
256
+ ```
257
+
258
+ 在 `packages/app/package.json` 中添加以下 script,在执行 `app` 仓库的部署命令之前,先执行 workspace 中其他仓库的构建:
259
+
260
+ ```json
261
+ {
262
+ "scripts": {
263
+ "build:packages": "pnpm --filter 'app^...' run build",
264
+ "deploy": "pnpm run build:packages && modern deploy",
265
+ }
266
+ }
267
+ ```
268
+
269
+ 在 `packages/app/vercel.json` 文件中添加以下内容:
270
+ ```json title="vercel.json"
271
+ {
272
+ "buildCommand": "npm run deploy",
273
+ "outputDirectory": ".vercel/output"
274
+ }
275
+ ```
276
+
277
+ 提交你的代码,使用 Vercel 平台部署即可。
278
+
279
+
176
280
 
177
281
 
@@ -460,8 +460,8 @@ export const init = (context: RuntimeContext) => {
460
460
  import { useRuntimeContext } from '@modern-js/runtime';
461
461
 
462
462
  export default () => {
463
- const { context } = useRuntimeContext();
464
- const { message } = context.getInitData();
463
+ const context = useRuntimeContext();
464
+ const { message } = context.initialData;
465
465
 
466
466
  return <div>{message}</div>;
467
467
  };
@@ -83,12 +83,6 @@ Modern.js 支持使用 [styled-components](https://styled-components.com/),请
83
83
 
84
84
  如果你需要使用其他 CSS-in-JS 方案,可以自行集成到你的项目中。
85
85
 
86
- ## 测试框架
87
-
88
- Modern.js 支持使用 [Jest](https://jestjs.io/) 进行单元测试或集成测试。该功能为可选功能,请参考[「使用 Jest 测试」](/guides/advanced-features/testing) 启用。
89
-
90
- 如果你需要使用 [Vitest](https://vitest.dev/) 或其他测试框架,可以自行集成到你的项目中。
91
-
92
86
  ## 组件库
93
87
 
94
88
  Modern.js 可以与社区中任意的 React 组件库搭配使用,比如 [MUI](https://mui.com/)、[Ant Design](https://ant.design/)、[Arco Design](https://github.com/arco-design/arco-design)、[Semi Design](https://semi.design/)、[Radix UI](https://www.radix-ui.com/) 等。
@@ -105,7 +105,7 @@ interface IAppContext {
105
105
  /** 服务端路由信息 */
106
106
  serverRoutes: ServerRoute[];
107
107
  /** 当前项目类型 */
108
- toolsType?: 'app-tools' | 'module-tools' | 'monorepo-tools';
108
+ toolsType?: 'app-tools' | 'module-tools';
109
109
  /** 当前使用的打包工具类型 */
110
110
  bundlerType?: 'webpack' | 'rspack' | 'esbuild';
111
111
  }
@@ -20,7 +20,6 @@ Options:
20
20
  -d,--debug 开启 Debug 模式,打印调试日志信息 (default: false)
21
21
  --mwa 一键创建 Web 应用(使用默认配置) (default: false)
22
22
  --module 一键创建 Module 应用(使用默认配置) (default: false)
23
- --monorepo 一键创建 Monorepo 应用(使用默认配置) (default: false)
24
23
  --generator <generator> 使用自定义生成器
25
24
  -p, --plugin <plugin> 使用生成器插件创建新的工程方案类型或定制化 Modern.js 工程方案 (default: [])
26
25
  --dist-tag <distTag> 生成项目时生成器使用特殊的 npm Tag (default: "")
@@ -89,10 +88,6 @@ npx @modern-js/create@latest --config '{"packageManager": "pnpm"}'
89
88
 
90
89
  快速创建 Npm 模块项目。
91
90
 
92
- ## --monorepo
93
-
94
- 快速创建 Monorepo 项目。
95
-
96
91
  ## -p, --plugin \<plugin>
97
92
 
98
93
  指定生成器插件。
@@ -4,7 +4,7 @@ sidebar_position: 1
4
4
 
5
5
  # 使用
6
6
 
7
- Modern.js 提供了 `@modern-js/create` 工具用于创建 Modern.js 提供的工程方案项目,例如 [Web 应用](https://modernjs.dev/)、[Npm 模块](https://modernjs.dev/module-tools)、[Monorepo](/guides/topic-detail/monorepo/intro.html) 等。
7
+ Modern.js 提供了 `@modern-js/create` 工具用于创建 Modern.js 提供的工程方案项目,例如 [Web 应用](https://modernjs.dev/)、[Npm 模块](https://modernjs.dev/module-tools)
8
8
 
9
9
  下面将介绍 `@modern-js/create` 的使用姿势。
10
10
 
@@ -47,12 +47,3 @@ npx @modern-js/create@latest npm-module
47
47
  ? 请选择开发语言 TS
48
48
  ? 请选择包管理工具 pnpm
49
49
  ```
50
-
51
- ### 创建 Monorepo
52
-
53
- ```bash
54
- npx @modern-js/create@latest monorepo
55
- ? 请选择你想创建的工程类型 Monorepo
56
- ? 请选择包管理工具 pnpm
57
- ```
58
-
@@ -60,8 +60,6 @@ sidebar_position: 3
60
60
 
61
61
  - 启用「微前端」模式 -- micro_frontend
62
62
 
63
- - 启用「单元测试 / 集成测试」功能 -- test
64
-
65
63
  - 启用「基于 UA 的 Polyfill」功能 -- polyfill
66
64
 
67
65
  - 启用「全局代理」 -- proxy
@@ -111,37 +109,8 @@ sidebar_position: 3
111
109
 
112
110
  选项:
113
111
 
114
- - 启用「单元测试 / 集成测试」功能 -- test
115
-
116
112
  - 启用 「Tailwind CSS」 支持 -- tailwindcss
117
113
 
118
114
  - 启用「Storybook」 -- storybook
119
115
 
120
116
  - 启用「Runtime API」 -- runtime_api
121
-
122
- ## Monorepo
123
-
124
- ### sub_solution
125
-
126
- 问题:请选择你想创建的工程类型
127
-
128
- 选项:
129
-
130
- - Web 应用 -- mwa
131
- - Npm 模块 -- module
132
-
133
- ### packageName
134
-
135
- 问题:请填写子项目名称
136
-
137
- :::info
138
- 子项目的 `package.json` 的 name 字段值,该配置值为字符串类型。
139
- :::
140
-
141
- ### packagePath
142
-
143
- 问题:请填写子项目目录名称
144
-
145
- :::info
146
- 子项目基于 apps 或者 packages 目录的子目录名称,该字段为字符串类型。
147
- :::
@@ -72,23 +72,3 @@ npm run new
72
72
  ```
73
73
 
74
74
  执行完成后将会在项目安装 Storybook 插件相关依赖,增加 `storybook` 命令,创建 `stories` 目录用于 Storybook 模块的开发并提供提示信息用于注册 Storybook 插件。
75
-
76
- ## Monorepo
77
-
78
- Monorepo 项目通过 `@modern-js/monorepo-tools` 提供 new 命令。
79
-
80
- new 命令提供了创建子项目的能力。
81
-
82
- 例如:
83
-
84
- 创建 Web 应用子项目:
85
-
86
- ```bash
87
- ? 请选择你想创建的工程类型 Web 应用
88
- ? 请填写子项目名称 web_app
89
- ? 请填写子项目目录名称 web_app
90
- ? 请选择开发语言 TS
91
- ? 请选择构建工具 webpack
92
- ```
93
-
94
- 执行完成后将会在项目 apps 目录创建 `web_app` 的子项目,在子项目目录中依然可以执行 new 命令创建项目元素和开启功能。
package/package.json CHANGED
@@ -15,17 +15,17 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.51.0",
18
+ "version": "2.53.0",
19
19
  "publishConfig": {
20
20
  "registry": "https://registry.npmjs.org/",
21
21
  "access": "public",
22
22
  "provenance": true
23
23
  },
24
24
  "dependencies": {
25
- "@modern-js/sandpack-react": "2.51.0"
25
+ "@modern-js/sandpack-react": "2.53.0"
26
26
  },
27
27
  "peerDependencies": {
28
- "@modern-js/builder-doc": "^2.51.0"
28
+ "@modern-js/builder-doc": "^2.53.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "classnames": "^2",
@@ -39,8 +39,8 @@
39
39
  "@rspress/shared": "1.18.2",
40
40
  "@types/node": "^16",
41
41
  "@types/fs-extra": "9.0.13",
42
- "@modern-js/builder-doc": "2.51.0",
43
- "@modern-js/doc-plugin-auto-sidebar": "2.51.0"
42
+ "@modern-js/builder-doc": "2.53.0",
43
+ "@modern-js/doc-plugin-auto-sidebar": "2.53.0"
44
44
  },
45
45
  "scripts": {
46
46
  "dev": "rspress dev",
@@ -1,4 +0,0 @@
1
- {
2
- "label": "Testing API",
3
- "position": 11
4
- }
@@ -1,35 +0,0 @@
1
- ---
2
- title: act
3
- ---
4
- # act
5
-
6
- Used to ensure that behaviors such as rendering, events, data fetching, etc. have been applied to the DOM.
7
-
8
- ## Usage
9
-
10
- ```ts
11
- import { act } from '@modern-js/runtime/testing';
12
- ```
13
-
14
- ## Function Signature
15
-
16
- `act` is the same as [react-dom/test-utils act function](https://reactjs.org/docs/testing-recipes.html#act).
17
-
18
- ## Example
19
-
20
- ```tsx
21
- import ReactDOM from 'react-dom';
22
- import { act } from '@modern-js/runtime/testing';
23
- import { Foo } from '@/components/Foo';
24
-
25
- describe('test act', () => {
26
- it('it should be foo', () => {
27
- const el = document.createElement('div');
28
- act(() => {
29
- ReactDOM.render(<Foo />, el);
30
- });
31
-
32
- expect(el.innerHTML).toBe('<div>Foo</div>');
33
- });
34
- });
35
- ```
@@ -1,40 +0,0 @@
1
- ---
2
- title: cleanup
3
- sidebar_position: 3
4
- ---
5
- # cleanup
6
-
7
- Used to uninstall all currently rendered components.
8
-
9
- ## Usage
10
-
11
- ```ts
12
- import { cleanup } from '@modenr-js/runtime/testing';
13
- ```
14
-
15
- ## Function Signature
16
-
17
- `function cleanup(): void`
18
-
19
- ## Example
20
-
21
- :::info
22
- Note that if you are using a testing framework that supports afterEach and it is injected into your testing environment (such as mocha, Jest, and Jasmine), **will execute `cleanup`** in the afterEach hook by default. Otherwise, you will need to do manual cleanup after each test.
23
-
24
- :::
25
-
26
- For example, if you use the [ava](https://github.com/avajs/ava) test framework, then you need to use the `test.after Each` hook like this.
27
-
28
- ```tsx
29
- import { cleanup, render } from '@modern-js/runtime/testing';
30
- import test from 'ava';
31
-
32
- test.afterEach(cleanup);
33
-
34
- test('renders into document', () => {
35
- render(<div />);
36
- // ...
37
- });
38
-
39
- // ... more tests ...
40
- ```
@@ -1,71 +0,0 @@
1
- ---
2
- title: render
3
- ---
4
- # render
5
-
6
- Used to render the component in the test case.
7
-
8
- ## Usage
9
-
10
- ```ts
11
- import { render } from '@modern-js/runtime/testing';
12
- ```
13
-
14
- ## Function Signature
15
-
16
- ```ts
17
- type Options = {
18
- container: DOMElement;
19
- baseElement: DOMElement;
20
- hydrate: boolean;
21
- warpper: React.ComponentType<{children: ReactNode}>;
22
- queries: any;
23
- };
24
-
25
- type RenderResult = {
26
- {...queries}: any;
27
- container: DOMElement;
28
- baseElement: DOMElement;
29
- debug: function;
30
- rerender: function;
31
- unmount: function;
32
- asFragment: function;
33
- }
34
-
35
- function render(ui: React.ReactElement<any>, options: Options): RenderResult;
36
- ```
37
-
38
- ### Input
39
-
40
- - `ui`: the React component that needs to be rendered.
41
- - `options`: render options.
42
- - `container`: the dom which component mounted. by default create a `div` element, and auto append to `document.body`. the default value is `document.body.append(document.createElement('div'))`.
43
- - `baseElement`: Used to specify the `basename` used in `queries`. If `container` is specified, the default value is the value of `container`, otherwise it is `document.body`.
44
- - `hydrate`: If set to `true`, the [ReactDOM.hydrate](https://react.dev/reference/react-dom/hydrate) rendering component is used. The default value is `false`.
45
- - `wrapper`: a react component that can be used to customize rendering logic.
46
- - `queries`: customize some own `queries`.
47
-
48
- ### Return Value
49
-
50
- - `{...queries}`: all available [queries](https://testing-library.com/docs/queries/about/).
51
- - `container`: the DOM element that React component mounted.
52
- - `baseElement`
53
- - `debug`
54
- - `rerender`: if you want to test some scene when a rendered component is updated, you can use rerender for reality.
55
- - `unmount`: unmount rendered components. This API is helpful if you want to test what happens after the component is unmounted.
56
- - `asFragment`: return the [DocumentFragment](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment) of rendered component. used to test the response of the DOM structure after the react event is triggered.
57
-
58
- ## Example
59
-
60
- ```ts
61
- import { render } from '@modern-js/runtime/testing';
62
- import App from './App';
63
-
64
- test('renders a message', () => {
65
- const { container, getByText } = render(<App />);
66
- expect(getByText('Hello, world!')).toBeInTheDocument();
67
- expect(container.firstChild).toMatchInlineSnapshot(`
68
- <h1>Hello, World!</h1>
69
- `);
70
- });
71
- ```
@@ -1,34 +0,0 @@
1
- ---
2
- title: renderApp
3
- ---
4
- # renderApp
5
-
6
- The `render` function is used to test normal components, and the `renderApp` function is used to test App components.
7
-
8
- ## Usage
9
-
10
- ```ts
11
- import { renderApp } from '@modern-js/runtime/testing';
12
- ```
13
-
14
- App components refer to components that contain some Modern.js contexts, such as App root components, Containers using Models, etc.
15
-
16
- For the testing of such components, you can use the `renderApp` function, which will automatically wrap the context information according to the current `modern.config.js`.
17
-
18
- ## Function Signature
19
-
20
- `renderApp` is the same as [render](./render.mdx).
21
-
22
- ## Example
23
-
24
- ```ts
25
- import { renderApp } from '@modern-js/runtime/testing';
26
- import App from './App';
27
-
28
- describe('test', () => {
29
- it('test App', () => {
30
- const { getByText } = renderApp(<App />);
31
- expect(getByText('Hello Modern!')).toBeInTheDocument();
32
- });
33
- });
34
- ```
@@ -1,4 +0,0 @@
1
- {
2
- "label": "testing",
3
- "position": 10
4
- }