@modern-js/main-doc 0.0.0-next-1685383616364 → 0.0.0-next-1685436485731

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 (86) hide show
  1. package/CHANGELOG.md +7 -2
  2. package/docs/en/apis/app/commands.mdx +5 -5
  3. package/docs/en/apis/app/hooks/api/api.mdx +80 -0
  4. package/docs/en/apis/app/hooks/api/app.mdx +12 -0
  5. package/docs/en/apis/app/hooks/api/lambda.mdx +57 -0
  6. package/docs/en/apis/app/hooks/api/test.mdx +1 -1
  7. package/docs/en/apis/app/hooks/config/html.mdx +2 -2
  8. package/docs/en/apis/app/hooks/config/icon.mdx +19 -19
  9. package/docs/en/apis/app/hooks/config/mock.mdx +1 -1
  10. package/docs/en/apis/app/hooks/config/public.mdx +10 -10
  11. package/docs/en/apis/app/hooks/config/storybook.mdx +3 -3
  12. package/docs/en/apis/app/hooks/config/upload.mdx +13 -13
  13. package/docs/en/apis/app/hooks/modern-config.mdx +4 -4
  14. package/docs/en/apis/app/hooks/server/index_.mdx +2 -9
  15. package/docs/en/apis/app/hooks/server/test.mdx +5 -2
  16. package/docs/en/apis/app/hooks/shared.mdx +1 -1
  17. package/docs/en/apis/app/hooks/src/app.mdx +17 -27
  18. package/docs/en/apis/app/hooks/src/index_.mdx +6 -6
  19. package/docs/en/apis/app/hooks/src/pages.mdx +41 -37
  20. package/docs/en/apis/app/hooks/src/routes.mdx +16 -36
  21. package/docs/en/apis/app/hooks/src/server.mdx +1 -1
  22. package/docs/en/apis/app/hooks/src/stories.mdx +6 -3
  23. package/docs/en/apis/app/hooks/src/test.mdx +4 -3
  24. package/docs/en/apis/app/runtime/web-server/hook.mdx +2 -2
  25. package/docs/en/apis/app/runtime/web-server/middleware.mdx +2 -2
  26. package/docs/en/components/init-app.mdx +3 -3
  27. package/docs/en/components/init-rspack-app.mdx +4 -4
  28. package/docs/en/components/ua-polyfill.mdx +2 -2
  29. package/docs/en/configure/app/tools/swc.mdx +2 -2
  30. package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -2
  31. package/docs/en/guides/advanced-features/bff/function.mdx +4 -4
  32. package/docs/en/guides/advanced-features/bff/type.mdx +5 -5
  33. package/docs/en/guides/advanced-features/rspack-start.mdx +2 -2
  34. package/docs/en/guides/advanced-features/ssg.mdx +2 -2
  35. package/docs/en/guides/advanced-features/testing.mdx +2 -2
  36. package/docs/en/guides/advanced-features/web-server.mdx +2 -2
  37. package/docs/en/guides/basic-features/css.mdx +2 -2
  38. package/docs/en/guides/basic-features/routes.mdx +11 -7
  39. package/docs/en/guides/concept/entries.mdx +3 -3
  40. package/docs/en/guides/topic-detail/generator/codesmith/develop.mdx +3 -3
  41. package/docs/en/guides/topic-detail/generator/plugin/develop.mdx +13 -13
  42. package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +8 -8
  43. package/docs/en/tutorials/first-app/c03-css.mdx +2 -2
  44. package/docs/en/tutorials/first-app/c08-entries.mdx +3 -3
  45. package/docs/zh/apis/app/commands.mdx +3 -3
  46. package/docs/zh/apis/app/hooks/api/{functions/api.mdx → api.mdx} +4 -4
  47. package/docs/zh/apis/app/hooks/api/app.mdx +12 -0
  48. package/docs/zh/apis/app/hooks/api/{framework/lambda.mdx → lambda.mdx} +5 -5
  49. package/docs/zh/apis/app/hooks/api/test.mdx +3 -3
  50. package/docs/zh/apis/app/hooks/config/icon.mdx +15 -15
  51. package/docs/zh/apis/app/hooks/config/mock.mdx +1 -1
  52. package/docs/zh/apis/app/hooks/config/public.mdx +3 -3
  53. package/docs/zh/apis/app/hooks/config/upload.mdx +1 -1
  54. package/docs/zh/apis/app/hooks/modern-config.mdx +3 -3
  55. package/docs/zh/apis/app/hooks/server/index_.mdx +1 -6
  56. package/docs/zh/apis/app/hooks/shared.mdx +1 -1
  57. package/docs/zh/apis/app/hooks/src/app.mdx +15 -25
  58. package/docs/zh/apis/app/hooks/src/index_.mdx +6 -6
  59. package/docs/zh/apis/app/hooks/src/pages.mdx +7 -3
  60. package/docs/zh/apis/app/hooks/src/routes.mdx +4 -4
  61. package/docs/zh/apis/app/hooks/src/stories.mdx +1 -1
  62. package/docs/zh/components/ua-polyfill.mdx +1 -1
  63. package/docs/zh/configure/app/tools/swc.mdx +2 -2
  64. package/docs/zh/guides/advanced-features/rspack-start.mdx +2 -2
  65. package/docs/zh/guides/advanced-features/ssg.mdx +1 -1
  66. package/docs/zh/guides/advanced-features/testing.mdx +2 -2
  67. package/docs/zh/guides/advanced-features/web-server.mdx +1 -1
  68. package/docs/zh/guides/basic-features/css.mdx +1 -1
  69. package/docs/zh/guides/basic-features/routes.mdx +7 -4
  70. package/docs/zh/guides/concept/entries.mdx +3 -3
  71. package/docs/zh/guides/topic-detail/generator/plugin/develop.mdx +14 -14
  72. package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +4 -4
  73. package/docs/zh/guides/topic-detail/model/test-model.mdx +1 -1
  74. package/docs/zh/tutorials/first-app/c03-css.mdx +1 -1
  75. package/docs/zh/tutorials/first-app/c08-entries.mdx +1 -1
  76. package/package.json +5 -5
  77. package/docs/en/apis/app/hooks/api/framework/_category_.json +0 -4
  78. package/docs/en/apis/app/hooks/api/framework/lambda.mdx +0 -57
  79. package/docs/en/apis/app/hooks/api/functions/_category_.json +0 -4
  80. package/docs/en/apis/app/hooks/api/functions/api.mdx +0 -81
  81. package/docs/en/apis/app/hooks/api/functions/app.mdx +0 -12
  82. package/docs/en/apis/app/hooks/api/functions/common.mdx +0 -9
  83. package/docs/zh/apis/app/hooks/api/framework/_category_.json +0 -4
  84. package/docs/zh/apis/app/hooks/api/functions/_category_.json +0 -4
  85. package/docs/zh/apis/app/hooks/api/functions/app.mdx +0 -12
  86. package/docs/zh/apis/app/hooks/api/functions/common.mdx +0 -9
@@ -12,9 +12,9 @@ Modern.js provides a microgenerator to create a microgenerator project, you can
12
12
  $ mkdir <projectDir>
13
13
  $ npx @modern-js/codesmith-cli @modern-js/generator-generator
14
14
 
15
- ? Package Name: <generatorName>
16
- ? Package Manager: pnpm
17
- ? Development Language: TS
15
+ ? Please fill in the project name: <generatorName>
16
+ ? Please select the package manager: pnpm
17
+ ? Please select the programming language: TS
18
18
  ```
19
19
 
20
20
  ## Add template file
@@ -17,25 +17,25 @@ Different plugin types will ask different questions. You can choose the plugin t
17
17
  ### Extension type
18
18
 
19
19
  ```
20
- ? Please select the solution you want to create: Npm Module
21
- ? Please select the scene you want to create: Generator Plugin
22
- ? Plugin Package Name: plugin
23
- ? Development Language: TS
24
- ? Package Manager: pnpm
25
- ? Plugin Type: extend
26
- ? Plugin Base Type: Web App
20
+ ? Please select the type of project you want to create: Npm Module
21
+ ? Please select the project scenario: Generator Plugin
22
+ ? Please fill in the package name of the generator plugin: plugin
23
+ ? Please select the programming language: TS
24
+ ? Please select the package manager: pnpm
25
+ ? Please select the type of plugin: extend
26
+ ? Please select the base type of the plugin: Web App
27
27
  ```
28
28
 
29
29
  ### Customized type
30
30
 
31
31
  ```
32
32
  ? Plugin Package Name: plugin
33
- ? Development Language: TS
34
- ? Package Manager: pnpm
35
- ? Plugin Type: custom
36
- ? Plugin Key: mobile-app
37
- ? Plugin Show Name: Mobile App
38
- ? Plugin Base Type: Web App
33
+ ? Please select the programming language: TS
34
+ ? Please select the package manager: pnpm
35
+ ? Please fill in the plugin keyword: custom
36
+ ? Please fill in the plugin keyword: mobile-app
37
+ ? Please fill in the display name of the plugin: Mobile App
38
+ ? Please select the base type of the plugin: Web App
39
39
  ```
40
40
 
41
41
  After the execution of the create project command is completed, a project for developing the generator plugin will be generated accordingly, and the `meta` information will also be generated according to your selection in the `package.json`.
@@ -33,8 +33,8 @@ npx @modern-js/create@latest
33
33
  After the project is created, we can enable the `micro frontend` through `pnpm run new`:
34
34
 
35
35
  ```bash
36
- ? Action Enable features
37
- ? Enable features Enable Micro Front-end Feature
36
+ ? Please select the operation you want: Enable features
37
+ ? Please select the feature name: Enable Micro Front-end Feature
38
38
  ```
39
39
 
40
40
  Next, let's register the micro frontend plugin and add the main micro frontend app and add the list of sub-apps:
@@ -115,8 +115,8 @@ npx @modern-js/create@latest
115
115
  After the project is created, we can enable the `micro frontend` function through `pnpm run new`:
116
116
 
117
117
  ```bash
118
- ? Action Enable features
119
- ? Enable features Enable Micro Front-end Feature
118
+ ? Please select the operation you want: Enable features
119
+ ? Please select the feature name: Enable Micro Front-end Feature
120
120
  ```
121
121
 
122
122
  Next, let's register the micro frontend plugin and add the main micro frontend app and add the list of sub-apps:
@@ -143,8 +143,8 @@ npx @modern-js/create@latest
143
143
  After create sub-app. We execute `pnpm run new` to enable the `micro frontend` function:
144
144
 
145
145
  ```bash
146
- ? Action Enable features
147
- ? Enable features Enable Micro Front-end Feature
146
+ ? Please select the operation you want: Enable features
147
+ ? Please select the feature name: Enable Micro Front-end Feature
148
148
  ```
149
149
 
150
150
  Next, let's register the micro frontend plugin and modify `modern.config.ts` to add the configuration of the micro frontend sub-app `deploy.microFrontend`:
@@ -192,8 +192,8 @@ npx @modern-js/create@latest
192
192
  After create sub-app. We execute `pnpm run new` to enable the `micro frontend` function:
193
193
 
194
194
  ```bash
195
- ? Action Enable features
196
- ? Enable features Enable Micro Front-end Feature
195
+ ? Please select the operation you want: Enable features
196
+ ? Please select the feature name: Enable Micro Front-end Feature
197
197
  ```
198
198
 
199
199
  Next, let's register the micro frontend plugin and modify `modern.config.ts` to add the configuration of the micro frontend sub-app `deploy.microFrontend`:
@@ -114,8 +114,8 @@ Modern.js integrates the mainstream, light, general-purpose Utility Class librar
114
114
  Execute `pnpm run new` and select the following to start Tailwind CSS:
115
115
 
116
116
  ```bash
117
- ? Action: Enable features
118
- ? Enable features: Enable Tailwind CSS
117
+ ? Please select the operation you want: Enable features
118
+ ? Please select the feature name: Enable Tailwind CSS
119
119
  ```
120
120
 
121
121
  Register the Tailwind plugin in `modern.config.ts`:
@@ -14,9 +14,9 @@ A complete project may require multiple entries, Modern.js supports the automati
14
14
  We can also use it to create new project elements and execute `pnpm run new` in the project root directory:
15
15
 
16
16
  ```bash
17
- ? Action Create project element
18
- ? Create project element New "entry"
19
- ? Entry name (entry) landing-page
17
+ ? Please select the operation you want: Create Element
18
+ ? Please select the type of element to create: New "entry"
19
+ ? Please fill in the entry name: landing-page
20
20
  ```
21
21
 
22
22
  When created, the project will look like this:
@@ -126,7 +126,7 @@ Options:
126
126
  ```bash
127
127
  $ npx modern new
128
128
  ? 请选择你想要的操作 创建工程元素
129
- ? 创建工程元素 新建「应用入口」
129
+ ? 请选择创建元素类型 新建「应用入口」
130
130
  ? 请填写入口名称 entry
131
131
  ```
132
132
 
@@ -137,8 +137,8 @@ $ npx modern new
137
137
  ```bash
138
138
  $ npx modern new
139
139
  ? 请选择你想要的操作 启用可选功能
140
- ? 启用可选功能 (Use arrow keys)
141
- ❯ 启用 Tailwind CSS 支持
140
+ ? 请选择功能名称 (Use arrow keys)
141
+ ❯ 启用 Tailwind CSS 支持
142
142
  启用「BFF」功能
143
143
  启用「微前端」模式
144
144
  启用「单元测试 / 集成测试」功能
@@ -4,7 +4,7 @@ sidebar_position: 1
4
4
  ---
5
5
  # **/*.[tj]s
6
6
 
7
- 在 BFF 函数写法下,声明 API 路由的文件。除了[某些约定文件](/apis/app/hooks/api/functions/api)外,`api` 目录下的文件会被注册为接口的路由。
7
+ [BFF 函数写法](/guides/advanced-features/bff/type.html#函数写法)下,声明 API 路由的文件。除了[某些约定文件](/apis/app/hooks/api/api#白名单)外,`api` 目录下的文件会被注册为接口的路由。
8
8
 
9
9
  :::info
10
10
  使用 `api` 目录需要开启 BFF 功能,需要在项目下执行 new 命令启用「BFF」功能。
@@ -31,7 +31,7 @@ sidebar_position: 1
31
31
 
32
32
  ### 动态路由
33
33
 
34
- 同样的,你可以通过创建带有 `[xxx]` 的文件夹或者文件来支持动态的命名路由参数。
34
+ 路由系统支持通过 `[]` 命名的文件目录生成动态路由。
35
35
 
36
36
  - `api/user/[username]/info.ts` -> `$BASENAME/user/:username/info`
37
37
  - `api/user/[username]/delete.ts` -> `$BASENAME/user/:username/delete`
@@ -64,7 +64,7 @@ export const get = async () => {
64
64
  };
65
65
  ```
66
66
 
67
- 这样导出函数,则会得到一个 `POST` 接口。
67
+ 这样导出函数,则会得到一个 `GET` 接口。
68
68
 
69
69
  应用工程中支持了 9 个 Method 定义,即:`GET`、`POST`、`PUT`、`DELETE`、`CONNECT`、`TRACE`、`PATCH`、`OPTION`、`HEAD`,即可以用这些 Method 作为函数导出的名字。
70
70
 
@@ -75,6 +75,6 @@ export const get = async () => {
75
75
  可以在一个文件中定义多个不同 Method 的函数,但如果定义多个相同 Method 的函数,则只有第一个会生效。
76
76
 
77
77
  :::info
78
- 需要注意的是,定义的函数都应该是异步的,这个与函数调用时类型有关,这个后面会提到。
78
+ 需要注意的是,定义的函数都应该是异步的,这个与函数调用时类型有关。
79
79
 
80
80
  :::
@@ -0,0 +1,12 @@
1
+ ---
2
+ title: _app.[tj]s
3
+ sidebar_position: 2
4
+ ---
5
+ # _app.[tj]s
6
+
7
+ 在 [BFF 函数写法](/guides/advanced-features/bff/type.html#函数写法)下,该文件可以为 BFF 函数添加前置中间件。
8
+
9
+ :::note
10
+ 具体示例请参考 [hook](/apis/app/runtime/bff/hook)
11
+
12
+ :::
@@ -1,10 +1,10 @@
1
1
  ---
2
2
  title: lambda/*.[tj]s
3
- sidebar_position: 1
3
+ sidebar_position: 3
4
4
  ---
5
5
  # lambda/*.[tj]s
6
6
 
7
- 在 BFF 框架写法下,声明 API 路由的文件。除了[某些约定文件](/apis/app/hooks/api/framework/lambda#白名单)外,`api/` 目录下的文件会被注册为接口的路由。
7
+ [BFF 框架写法](/guides/advanced-features/bff/type.html#框架写法)下,声明 API 路由的文件。除了[某些约定文件](/apis/app/hooks/api/lambda#白名单)外,`lambda/` 目录下的文件会被注册为接口的路由。
8
8
 
9
9
  :::info
10
10
  使用 `api` 目录需要开启 BFF 功能,需要在项目下执行 new 命令启用「BFF」功能。
@@ -34,7 +34,7 @@ sidebar_position: 1
34
34
 
35
35
  ### 动态路由
36
36
 
37
- 同样的,你可以通过创建带有 `[xxx]` 的文件夹或者文件来支持动态的命名路由参数。
37
+ 路由系统支持通过 `[]` 命名的文件目录生成动态路由。
38
38
 
39
39
  - `api/lambda/user/[username]/info.ts` -> `$BASENAME/user/:username/info`
40
40
  - `api/lambda/user/[username]/delete.ts` -> `$BASENAME/user/:username/delete`
@@ -44,7 +44,7 @@ sidebar_position: 1
44
44
 
45
45
  ### 白名单
46
46
 
47
- 默认 `api` 目录下所有文件都会当作 BFF 函数文件去解析,但同样我们也设置了白名单,这些文件不被被解析:
47
+ 默认 `lambda` 目录下所有文件都会当作 BFF 函数文件去解析,但同样我们也设置了白名单,这些文件不被被解析:
48
48
 
49
49
  - 命名以 `_` 开头的文件。例如:`_utils.ts`。
50
50
  - 命名以 `_` 开头的文件夹下所有文件。例如:`_utils/index.ts`、`_utils/cp.ts`。
@@ -54,4 +54,4 @@ sidebar_position: 1
54
54
 
55
55
  ## 函数定义
56
56
 
57
- 和函数写法下[函数定义](/apis/app/hooks/api/functions/api#define-function)完全一致。
57
+ 和函数写法下[函数定义](/apis/app/hooks/api/api#函数定义)完全一致。
@@ -1,12 +1,12 @@
1
1
  ---
2
2
  title: test.[tj]s
3
- sidebar_position: 2
3
+ sidebar_position: 4
4
4
  ---
5
5
  # test.[tj]s
6
6
 
7
- 应用的 BFF 测试文件,支持在 `api/` 目录后缀为 `.test.[tj]sx?` 的文件中编写测试用例。
7
+ The BFF test file of the application supports writing test cases in files with the suffix `.test.[tj]sx?` under the `api/` directory.
8
8
 
9
9
  :::info
10
- 使用单元测试、集成测试需要提前在项目下执行 new 命令启用「单元测试 / 集成测试」功能。
10
+ Enabling unit testing and integration testing requires running the new command to enable the "Unit Testing/Integration Testing" function under the project first.
11
11
 
12
12
  :::
@@ -1,11 +1,11 @@
1
1
  ---
2
- title: icon
2
+ title: icon/
3
3
  sidebar_position: 2
4
4
  ---
5
5
 
6
- # Icon
6
+ # icon/
7
7
 
8
- ## 设置 favicon
8
+ ## Favicon
9
9
 
10
10
  当项目根目录的 `config` 目录下存在 `favicon.*` 文件时,Modern.js 会自动将该文件设置到 [html.favicon](/configure/app/html/favicon) 配置项中,用于生成页面的 favicon 图标:
11
11
 
@@ -24,15 +24,15 @@ sidebar_position: 2
24
24
 
25
25
  在设置 app icon 时,Modern.js 会按以下顺序寻找文件:
26
26
 
27
- - favicon.png
28
- - favicon.jpg
29
- - favicon.jpeg
30
- - favicon.svg
31
- - favicon.ico
27
+ - `favicon.png`
28
+ - `favicon.jpg`
29
+ - `favicon.jpeg`
30
+ - `favicon.svg`
31
+ - `favicon.ico`
32
32
 
33
- ## 设置 app icon
33
+ ## Apple Touch Icon
34
34
 
35
- 当项目根目录的 `config` 目录下存在 `icon.*` 文件时,Modern.js 会自动将该文件设置到 [html.appIcon](/configure/app/html/app-icon) 配置项中,用于生成 iOS 系统下的 apple-touch-icon 图标。
35
+ 当项目根目录的 `config` 目录下存在 `icon.*` 文件时,Modern.js 会自动将该文件设置到 [html.appIcon](/configure/app/html/app-icon) 配置项中,用于生成 iOS 系统下的 Apple Touch Icon 图标。
36
36
 
37
37
  ```
38
38
  ./config
@@ -49,8 +49,8 @@ sidebar_position: 2
49
49
 
50
50
  在设置 app icon 时,Modern.js 会按以下顺序寻找文件:
51
51
 
52
- - icon.png
53
- - icon.jpg
54
- - icon.jpeg
55
- - icon.svg
56
- - icon.ico
52
+ - `icon.png`
53
+ - `icon.jpg`
54
+ - `icon.jpeg`
55
+ - `icon.svg`
56
+ - `icon.ico`
@@ -4,4 +4,4 @@ sidebar_position: 5
4
4
  ---
5
5
  # mock/
6
6
 
7
- 项目根目录下存在 `config/mock/index.js` 时,在开发环节自动开启 Mock 服务。
7
+ 当项目目录下存在 `config/mock/index.js` 时,Modern.js 在开发环节将自动开启 Mock 服务。
@@ -4,13 +4,13 @@ sidebar_position: 3
4
4
  ---
5
5
  # public/
6
6
 
7
- `public/` 目录中可以放置任意格式的静态资源文件,文件会被 Serve 在 Web 应用域名下。
7
+ `public/` 目录中可以放置任意格式的静态资源文件,文件会被服务端部署到对应的应用域名下。
8
8
 
9
9
  ## 说明
10
10
 
11
- 被 Serve 的文件路由基于目录结构的约定,其中,`public/` 为根目录,对应 Web 应用根路径。
11
+ 文件路由基于目录结构的约定,其中,`public/` 为根目录,对应 Web 应用根路径。
12
12
 
13
- 例如 `config/public/sdk/index.js` 文件,在部署后将会被 Serve 在 `${domain}/sdk/index.js` 下。
13
+ 例如 `config/public/sdk/index.js` 文件,在部署后将会被部署在 `${domain}/sdk/index.js` 下。
14
14
 
15
15
  ## 场景
16
16
 
@@ -14,7 +14,7 @@ sidebar_position: 4
14
14
 
15
15
  ## 场景
16
16
 
17
- 例如 `google-analysis.js` 等项目自用的 SDK(通常需要 http 缓存)。
17
+ 例如 `google-analysis.js` 等项目自用的 SDK(通常需要 HTTP 缓存)。
18
18
 
19
19
  图片、字体文件、通用 CSS 等。
20
20
 
@@ -1,9 +1,9 @@
1
1
  ---
2
- title: modern.config.js
2
+ title: modern.config.[tj]s
3
3
  sidebar_position: 8
4
4
  ---
5
- # modern.config.js
5
+ # modern.config.[tj]s
6
6
 
7
7
  Modern.js 配置文件, 通过该文件可以对当前项目的各个方面进行个性化配置。
8
8
 
9
- 了解配置的具体用法,请参考 [配置使用](/configure/app/usage)。
9
+ 了解配置的具体用法,请参考[配置使用](/configure/app/usage)。
@@ -4,11 +4,6 @@ sidebar_position: 1
4
4
  ---
5
5
  # index.[tj]s
6
6
 
7
- 扩展 Modern.js Web Server 的文件,在此文件中可以给应用工程启动的 Web Server 添加 Hook 或 Middleware。
7
+ 扩展 Modern.js Web Server 的文件,在此文件中可以给应用工程启动的 Web Server 添加 [Hook](/apis/app/runtime/web-server/hook)[Middleware](/apis/app/runtime/web-server/middleware)
8
8
 
9
9
  可以对请求和响应进行拦截处理,鉴权与角色、请求预处理、异常兜底等。也可在内置处理逻辑(包括路由匹配、资源寻址、头部注入、页面渲染,静态 Web 托管)插入特定的业务逻辑。
10
-
11
- :::info
12
- 具体使用示例可查看 [Hook](/apis/app/runtime/web-server/hook) & [Middleware](/apis/app/runtime/web-server/middleware)。
13
-
14
- :::
@@ -4,4 +4,4 @@ sidebar_position: 5
4
4
  ---
5
5
  # shared/
6
6
 
7
- 共享源码目录。当项目在 `api/`、`server/`、`src/` 下有公共代码时,可将这些代码放到 shared 目录下,而不是直接引用。
7
+ 共享源码目录。当项目在 `api/`、`server/`、`src/` 下有公共代码时,可将这些代码放到 `shared` 目录下,而不是直接引用。
@@ -4,46 +4,36 @@ sidebar_position: 1
4
4
  ---
5
5
  # App.[tj]sx
6
6
 
7
- 应用使用自控路由时的入口标识符。
7
+ 应用使用[自控路由](/guides/basic-features/routes.html#self-controlled-routing)时的入口标识符。
8
8
 
9
9
  `App.[tj]sx` 并不是实际的应用入口,Modern.js 会自动生成真正的构建打包的入口文件, 内容大致如下:
10
10
 
11
11
  ```js
12
12
  import React from 'react';
13
+ import ReactDOM from 'react-dom/client';
13
14
  import { createApp, bootstrap } from '@modern-js/runtime';
14
15
  // App.[jt]sx
15
16
  import App from '@_modern_js_src/App';
16
- import { state } from '@modern-js/runtime/plugins';
17
- import {
18
- immer,
19
- effects,
20
- autoActions,
21
- devtools,
22
- } from '@modern-js/runtime/model';
23
-
24
- const createStatePlugins = config => {
25
- const plugins = [];
26
- plugins.push(immer(config['immer']));
27
- plugins.push(effects(config['effects']));
28
- plugins.push(autoActions(config['autoActions']));
29
- plugins.push(devtools(config['devtools']));
30
- return plugins;
31
- };
17
+ // runtime plugin
18
+ import { router } from '@modern-js/runtime/plugins';
19
+
20
+ const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
21
+ const MOUNT_ID = 'root';
22
+
32
23
  let AppWrapper = null;
24
+
33
25
  function render() {
34
26
  AppWrapper = createApp({
35
27
  plugins: [
36
- state({
37
- ...{ plugins: createStatePlugins(true) },
38
- ...App?.config?.state,
39
- }),
40
- ],
41
- })(App);
28
+ router({...{"serverBase":["/"]}, ...App.config?.router}),
29
+ ]
30
+ })(App)
42
31
  if (IS_BROWSER) {
43
- bootstrap(AppWrapper, MOUNT_ID);
32
+ bootstrap(AppWrapper, MOUNT_ID, null, ReactDOM);
44
33
  }
45
- return AppWrapper;
34
+ return AppWrapper
46
35
  }
36
+
47
37
  AppWrapper = render();
48
38
  export default AppWrapper;
49
39
  ```
@@ -4,13 +4,13 @@ sidebar_position: 4
4
4
  ---
5
5
  # index.[tj]s
6
6
 
7
- 应用项目入口标识。
7
+ 应用使用自定义 `bootstrap` 时的入口标识。
8
8
 
9
- 通常情况下 [`src/App.[tj]sx, src/[entry]/App.[tj]sx`](/apis/app/hooks/src/app) 钩子文件已经能满足我们的需求,当我们需要在 `bootstrap` 之前添加自定义行为或者完全接管 webpack 打包入口时,可以在 `src` 或者入口目录下放置 `index.[tj]s`。 下面有分两种情况进行讨论:
9
+ 通常情况下 [`App.[tj]sx`](/apis/app/hooks/src/app) 钩子文件已经能满足我们的需求,当我们需要在 `bootstrap` 之前添加自定义行为或者完全接管 webpack 打包入口时,可以在 `src` 或者入口目录下放置 `index.[tj]s`。 下面有分两种情况进行讨论:
10
10
 
11
- 1. 在 bootstrap 之前添加自定义行为:
11
+ ## 在 bootstrap 之前添加自定义行为
12
12
 
13
- 只需要 `src/index.[tj]s` 默认导出函数:
13
+ 只需要 `src/index.[tj]s` 默认导出函数:
14
14
 
15
15
  ```js title=src/index.js
16
16
  import ReactDOM from 'react-dom/client';
@@ -22,9 +22,9 @@ export default (App: React.ComponentType) => {
22
22
  };
23
23
  ```
24
24
 
25
- 2. 完全接管 webpack 入口:
25
+ ## 完全接管 webpack 入口
26
26
 
27
- 当 `src/index.[tj]sx?` 下没有默认导出函数时,该文件即为真正的 webpack 打包入口文件, 可以直接像使用 create-react-app 等脚手架一样组织代码:
27
+ 当 `src/index.[tj]sx?` 下没有默认导出函数时,该文件即为真正的 webpack 打包入口文件, 可以直接像使用 create-react-app 等脚手架一样组织代码:
28
28
 
29
29
  ```js title=src/index.jsx
30
30
  import React from 'react';
@@ -4,9 +4,13 @@ sidebar_position: 3
4
4
  ---
5
5
  # pages/
6
6
 
7
- 应用使用基于文件系统路由时的入口标识。
7
+ 应用使用 [`Pages` 入口](https://modernjs.dev/v1/docs/guides/usages/entries#pages-%E5%85%A5%E5%8F%A3)时的入口标识。
8
8
 
9
- 当项目结构为 `Pages 入口` 类型时, 会分析 `src/pages` 目录下的文件得到客户端路由配置。
9
+ :::info
10
+ 兼容 Modern.js 1.0 `Pages` 入口,推荐使用[约定式路由](guides/basic-features/routes.html#约定式路由)。
11
+ :::
12
+
13
+ 当项目结构为 `Pages 入口`类型时, 会分析 `src/pages` 目录下的文件得到客户端路由配置。
10
14
 
11
15
  举例说明,例如以下目录结构:
12
16
 
@@ -20,7 +24,7 @@ sidebar_position: 3
20
24
  └── info.jsx
21
25
  ```
22
26
 
23
- 对应生成的路由配置为:
27
+ 对应生成的路由配置为:
24
28
 
25
29
  ```bash
26
30
  [
@@ -4,13 +4,13 @@ sidebar_position: 2
4
4
  ---
5
5
  # routes/
6
6
 
7
- 应用使用基于文件系统路由时的入口标识。
7
+ 应用使用[约定式路由](guides/basic-features/routes.html#约定式路由)时的入口标识。
8
8
 
9
- 当项目结构为 `Routes 入口` 类型时, 会分析 `src/routes` 目录下的文件得到客户端路由配置。具体用法请查看[约定式路由](/guides/basic-features/routes)
9
+ 约定式路由以 `routes/` 为约定的入口, 会分析 `src/routes` 目录下的文件得到客户端路由配置。
10
10
 
11
11
  任何在 `src/routes` 下的 `layout.[tj]sx` 和 `page.[tj]sx` 都会作为应用的路由:
12
12
 
13
- ```bash {3}
13
+ ```bash {3,4}
14
14
  .
15
15
  └── routes
16
16
  ├── layout.tsx
@@ -54,7 +54,7 @@ sidebar_position: 2
54
54
 
55
55
  在组件中,可以通过 [useParams](/apis/app/runtime/router/router#useparams) 获取对应命名的参数。
56
56
 
57
- loader 中,params 会作为 [loader](/guides/basic-features/data-fetch#loader-函数) 的入参,通过 `params` 的属性可以获取到对应的参数。
57
+ 在使用 [loader](/guides/basic-features/data-fetch#loader-函数) 函数获取数据时,`params` 会作为 `loader` 函数的入参,通过 `params` 的属性可以获取到对应的参数。
58
58
 
59
59
  ## 布局组件
60
60
 
@@ -8,7 +8,7 @@ sidebar_position: 7
8
8
 
9
9
  可以在项目源码目录 `src/` 下创建 `*.stories.[tj]sx` 格式的文件作为 Storybook 的调试文件。
10
10
 
11
- 在项目下执行 dev story 命令,支持使用这些文件在 Storybook 中对相关内容进行调试。
11
+ 在项目下执行 `npm run dev story` 命令,支持使用这些文件在 Storybook 中对相关内容进行调试。
12
12
 
13
13
  :::info
14
14
  使用 Storybook 需要提前在项目下执行 new 命令启用「Visual Testing (Storybook)」模式。
@@ -9,7 +9,7 @@ Modern.js 中还提供了基于浏览器 [UA](https://developer.mozilla.org/zh-C
9
9
 
10
10
  ```bash
11
11
  ? 请选择你想要的操作 启用可选功能
12
- ? 启用可选功能 启用「基于 UA 的 Polyfill」功能
12
+ ? 请选择功能名称 启用「基于 UA 的 Polyfill」功能
13
13
  ```
14
14
 
15
15
  执行命令后,在 `modern.config.ts` 中注册 Polyfill 插件:
@@ -22,8 +22,8 @@ import SWC from '@modern-js/builder-doc/docs/zh/shared/swc.md';
22
22
  首先,你需要执行 `pnpm run new` 启用 SWC 编译:
23
23
 
24
24
  ```bash
25
- ? 请选择你想要的操作:启用可选功能
26
- ? 启用可选功能:启用「SWC 编译」
25
+ ? 请选择你想要的操作 启用可选功能
26
+ ? 请选择功能名称 启用「SWC 编译」
27
27
  ```
28
28
 
29
29
  执行完成后,你只需在 `modern.config.ts` 文件中注册 SWC 插件,即可启用 SWC 编译和压缩能力。
@@ -37,8 +37,8 @@ import InitRspackApp from '@site-docs/components/init-rspack-app';
37
37
 
38
38
  ```bash
39
39
  $ pnpm run new
40
- ? 请选择你想要的操作:启用可选功能
41
- ? 启用可选功能:启用「Rspack 构建」
40
+ ? 请选择你想要的操作 启用可选功能
41
+ ? 请选择功能名称 启用「Rspack 构建」
42
42
  ```
43
43
 
44
44
  执行以上命令后,在 `modern.config.ts` 中添加 Rspack 相关配置即可:
@@ -10,7 +10,7 @@ SSG(Static Site Generation)是一种基于数据与模板,在构建时渲
10
10
 
11
11
  ```bash
12
12
  ? 请选择你想要的操作 启用可选功能
13
- ? 启用可选功能 启用「SSG」功能
13
+ ? 请选择功能名称 启用「SSG」功能
14
14
  ```
15
15
 
16
16
  执行命令后,在 `modern.config.ts` 中注册 SSG 插件:
@@ -9,8 +9,8 @@ Modern.js 默认集成了 [Jest](https://jestjs.io/) 的测试能力。
9
9
  我们首先需要执行 `pnpm run new` 启用「单元测试 / 集成测试」功能:
10
10
 
11
11
  ```
12
- ? 请选择你想要的操作: 启用可选功能
13
- ? 启用可选功能: 启用「单元测试 / 集成测试」功能
12
+ ? 请选择你想要的操作 启用可选功能
13
+ ? 请选择功能名称 启用「单元测试 / 集成测试」功能
14
14
  ```
15
15
 
16
16
  执行上述命令后,`package.json` 中将会自动生成 `"test": "modern test"` 命令。
@@ -26,7 +26,7 @@ Modern.js 作为以客户端为中心的开发框架,对服务端的定制能
26
26
 
27
27
  ```bash
28
28
  ? 请选择你想要的操作 创建工程元素
29
- ? 创建工程元素 新建「自定义 Web Server」源码目录
29
+ ? 请选择创建元素类型 新建「自定义 Web Server」源码目录
30
30
  ```
31
31
 
32
32
  执行命令后,在 `modern.config.ts` 中注册 `@modern-js/plugin-server` 插件:
@@ -67,7 +67,7 @@ Modern.js 内部集成了 Babel 的 [babel-plugin-styled-components](https://git
67
67
 
68
68
  ```bash
69
69
  ? 请选择你想要的操作 启用可选功能
70
- ? 启用可选功能 启用 Tailwind CSS 支持
70
+ ? 请选择功能名称 启用 Tailwind CSS 支持
71
71
  ```
72
72
 
73
73
  在 `modern.config.ts` 中注册 Tailwind 插件: