@modern-js/main-doc 0.0.0-next-20221123182933 → 0.0.0-next-20221124071519

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 (70) hide show
  1. package/CHANGELOG.md +3 -2
  2. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/_category_.json +1 -1
  3. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/build.md +10 -10
  4. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/dev.md +7 -7
  5. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/index.md +2 -2
  6. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/inspect.md +15 -15
  7. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/lint.md +2 -2
  8. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/new.md +15 -15
  9. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/start.md +5 -5
  10. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/test.md +5 -5
  11. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/upgrade.md +7 -9
  12. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/_category_.json +1 -1
  13. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/framework/lambda.md +22 -47
  14. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/functions/api.md +46 -18
  15. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/functions/app.md +2 -2
  16. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/functions/common.md +4 -4
  17. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/test.md +2 -4
  18. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/html.md +2 -4
  19. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/icon.md +3 -5
  20. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/mock.md +1 -7
  21. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/public.md +11 -13
  22. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/storybook.md +3 -5
  23. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/upload.md +14 -20
  24. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/index.md +2 -7
  25. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/modern-config.md +2 -4
  26. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/server/index_.md +5 -3
  27. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/server/test.md +2 -4
  28. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/shared.md +1 -3
  29. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/app.md +7 -3
  30. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/index_.md +7 -8
  31. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/pages.md +40 -43
  32. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/stories.md +3 -5
  33. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/test.md +3 -3
  34. package/en/docusaurus-plugin-content-docs/current/apis/app/overview.md +3 -2
  35. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/app/define-config.md +2 -2
  36. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/default-alias.md +0 -1
  37. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/env.md +1 -1
  38. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/model_.md +2 -2
  39. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/testing/act.md +1 -1
  40. package/en/docusaurus-plugin-content-docs/current.json +10 -10
  41. package/package.json +3 -3
  42. package/zh/apis/app/commands/build.md +1 -1
  43. package/zh/apis/app/commands/index.md +1 -1
  44. package/zh/apis/app/commands/lint.md +1 -1
  45. package/zh/apis/app/commands/upgrade.md +0 -2
  46. package/zh/apis/app/hooks/api/framework/_category_.json +1 -1
  47. package/zh/apis/app/hooks/api/framework/lambda.md +7 -32
  48. package/zh/apis/app/hooks/api/functions/_category_.json +1 -1
  49. package/zh/apis/app/hooks/api/functions/api.md +28 -1
  50. package/zh/apis/app/hooks/api/functions/common.md +2 -4
  51. package/zh/apis/app/hooks/api/test.md +1 -3
  52. package/zh/apis/app/hooks/config/html.md +0 -2
  53. package/zh/apis/app/hooks/config/icon.md +1 -1
  54. package/zh/apis/app/hooks/config/mock.md +1 -7
  55. package/zh/apis/app/hooks/config/public.md +1 -3
  56. package/zh/apis/app/hooks/config/storybook.md +1 -3
  57. package/zh/apis/app/hooks/config/upload.md +0 -6
  58. package/zh/apis/app/hooks/modern-config.md +1 -3
  59. package/zh/apis/app/hooks/server/index_.md +4 -4
  60. package/zh/apis/app/hooks/server/test.md +1 -1
  61. package/zh/apis/app/hooks/shared.md +1 -2
  62. package/zh/apis/app/hooks/src/app.md +7 -3
  63. package/zh/apis/app/hooks/src/index_.md +1 -1
  64. package/zh/apis/app/hooks/src/pages.md +2 -3
  65. package/zh/apis/app/hooks/src/stories.md +1 -1
  66. package/zh/apis/app/overview.md +1 -1
  67. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/framework/app.md +0 -100
  68. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/eslint.md +0 -9
  69. package/zh/apis/app/hooks/api/framework/app.md +0 -100
  70. package/zh/apis/app/hooks/src/eslint.md +0 -9
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @modern-js/main-doc
2
2
 
3
- ## 0.0.0-next-20221123182933
3
+ ## 0.0.0-next-20221124071519
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -11,6 +11,7 @@
11
11
  - Updated dependencies [2bc090c0]
12
12
  - Updated dependencies [f96a7252]
13
13
  - Updated dependencies [57077b2c]
14
+ - Updated dependencies [2ff6167b]
14
15
  - Updated dependencies [5402fdb0]
15
16
  - Updated dependencies [10d08a48]
16
17
  - Updated dependencies [5d67c26c]
@@ -19,4 +20,4 @@
19
20
  - Updated dependencies [3fae2d03]
20
21
  - Updated dependencies [df41d71a]
21
22
  - Updated dependencies [14b712da]
22
- - @modern-js/builder-doc@0.0.0-next-20221123182933
23
+ - @modern-js/builder-doc@0.0.0-next-20221124071519
@@ -1,5 +1,5 @@
1
1
  {
2
- "label": "命令",
2
+ "label": "Commands",
3
3
  "position": 3,
4
4
  "link": {
5
5
  "type": "doc",
@@ -8,18 +8,18 @@ Usage: modern build [options]
8
8
  build application
9
9
 
10
10
  Options:
11
- -c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
12
- -h, --help 显示命令帮助
13
- --analyze 分析构建产物体积,查看各个模块打包后的大小
11
+ -c --config <config> configuration file path, which can be a relative path or an absolute path
12
+ -h, --help show command help
13
+ --analyze analyze the bundle and view size of each module
14
14
  ```
15
15
 
16
- `modern build` 命令默认会在 `/dist` 目录下构建出可用于生产环境的产物。
16
+ `modern build` command will by default build production in `dist/`.
17
17
 
18
- 可以通过修改配置 [`output.distPath`](/docs/configure/app/output/dist-path) 指定产物的输出目录。
18
+ you can configure the [`output.distPath`](/docs/configure/app/output/dist-path) specifies the output directory for the product.
19
19
 
20
- ## 分析构建产物体积
20
+ ## Analyze Bundle
21
21
 
22
- 执行 `npx modern build --analyze` 命令,可以在打包生产环境代码的同时,产出一个分析构建产物体积的 HTML 文件:
22
+ execute `npx modern build --analyze` command,can produce an HTML file that analyzes the volume of the bundle while packaging the production code:
23
23
 
24
24
  ```
25
25
  Bundle Analyzer saved report to /example/dist/report.html
@@ -31,13 +31,13 @@ File sizes after production build:
31
31
  645 B dist/static/css/main.0dd3ecc1.css
32
32
  ```
33
33
 
34
- 手动在浏览器中打开上述 HTML 文件,可以看到打包产物的瓦片图,并进行包体积分析和优化:
34
+ Open the above HTML file in the browser, you can see the tile diagram of the packaged product, and perform package volume analysis and optimization:
35
35
 
36
36
  <img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/mwa-build-analyze-8784f762c1ab0cb20935829d5f912c4c.png" />
37
37
 
38
- > 该功能基于 [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) 实现。
38
+ > this features based on [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer).
39
39
 
40
- ## 命令行参数
40
+ ## Command Arguments
41
41
 
42
42
  import CommandTip from '@site-docs/components/command-tip.md'
43
43
 
@@ -7,17 +7,17 @@ sidebar_position: 1
7
7
  ```bash
8
8
  Usage: modern dev [options]
9
9
 
10
- 本地开发命令
10
+ Development commands
11
11
 
12
12
  Options:
13
- -e --entry <entry> 指定入口,编译特定的页面
14
- -c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
15
- -h, --help 显示命令帮助
16
- --analyze 分析构建产物体积,查看各个模块打包后的大小
17
- --api-only 仅启动 API 接口服务
13
+ -e --entry <entry> compiler by entry
14
+ -c --config <config> configuration file path, which can be a relative path or an absolute path
15
+ -h, --help show command help
16
+ --analyze analyze the bundle and view size of each module
17
+ --api-only only start API service
18
18
  ```
19
19
 
20
- `modern dev` 命令启动一个开发服务器,同时监听源文件变化,默认支持 React Fast Refresh
20
+ `modern dev` start a development server,watch file change,default support React Fast Refresh:
21
21
 
22
22
  ```bash
23
23
  App running at:
@@ -2,9 +2,9 @@
2
2
  type: ref
3
3
  ---
4
4
 
5
- # 命令
5
+ # Commands
6
6
 
7
- 本节涵盖了使用应用工程的所有命令。
7
+ This section covers all commands.
8
8
 
9
9
 
10
10
 
@@ -8,32 +8,32 @@ Usage: modern inspect [options]
8
8
  inspect internal webpack config
9
9
 
10
10
  Options:
11
- --env <env> 查看指定环境下的配置 (default: "development")
12
- --output <output> 指定在 dist 目录下输出的路径 (default: "/")
13
- --no-console 不在终端中输出完整结果
14
- --verbose 在结果中展示函数的完整内容
15
- -c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
16
- -h, --help 显示命令帮助
11
+ --env <env> view the configuration in the target environment (default: "development")
12
+ --output <output> Specify the path to output in the dist (default: "/")
13
+ --no-console Do not output the full result in shell
14
+ --verbose Show the full function in the result
15
+ -c --config <config> configuration file path, which can be a relative path or an absolute path
16
+ -h, --help show command help
17
17
  ```
18
18
 
19
- `modern inspect` 命令,用于查看项目的 webpack 完整配置。
19
+ `modern inspect` command used to view the full webpack configuration of the project.
20
20
 
21
- 在项目根目录下执行命令 `npx modern inspect`,会将 webpack 配置输出在终端界面,同时也会在项目的 `dist` 目录生成一份 `webpack.client.inspect.js` 文件,开发者可手动打开查看。
21
+ Executing the command `npx modern inspect` in the project will output the webpack configuration on the shell, and will also generate a `webpack.client.inspect.js` file in the project's `dist` directory, which developers can open and view manually.
22
22
 
23
- ## 指定环境
23
+ ## Configuration Env
24
24
 
25
- 默认情况下,会输出开发环境的 webpack 配置,可以使用 `env` 选项来输出生产环境的配置:
25
+ By default, the webpack configuration of the development environment is output. And the `env` option can be used to output the configuration of the production environment:
26
26
 
27
27
  ```bash
28
28
  modern inspect --env production
29
29
  ```
30
30
 
31
- ## 配置类型
31
+ ## Configuration Type
32
32
 
33
- ### SSR 配置
33
+ ### SSR Configuration
34
34
 
35
- 如果项目开启了 SSR 能力,则在 `dist` 目录会另外生成一份 `webpack.ssr.inspect.js` 文件,对应 SSR 构建时的 webpack 配置。
35
+ If the project has SSR enable, an additional `webpack.ssr.inspect.js` file will be generated in the `dist/`, corresponding to the webpack configuration at SSR build time.
36
36
 
37
- ### Modern 配置
37
+ ### Modern Configuration
38
38
 
39
- 如果项目开启了 [enableModernMode](/docs/configure/app/output/enable-modern-mode) 选项,则在 `dist` 目录会另外生成一份 `webpack.modern.inspect.js` 文件,对应现代浏览器的 webpack 配置。
39
+ if project enable [enableModernMode](/docs/configure/app/output/enable-modern-mode), an additional `webpack.modern.inspect.js` file will be generated in the `dist/`corresponding to the webpack configuration at modern web build.
@@ -13,9 +13,9 @@ Options:
13
13
  -h, --help display help for command
14
14
  ```
15
15
 
16
- 运行 `ESLint` 检查代码语法情况, 通长情况下,我们只需要在 `git commit` 阶段通过 `lint-staged` 检查本次提交修改的部分代码。
16
+ Run ESLint to check the syntax of the code. Normally, only the part of the code modified by this commit needs to be checked by `lint-staged` during the `git commit` phase.
17
17
 
18
- * `--no-fix` 参数设置后可以关闭自动修复 lint 错误代码的能力。
18
+ * `--no-fix` close auto fix by lint.
19
19
 
20
20
  import CommandTip from '@site-docs/components/command-tip.md'
21
21
 
@@ -5,27 +5,27 @@ sidebar_position: 2
5
5
  ```bash
6
6
  Usage: modern new [options]
7
7
 
8
- 应用工程中执行生成器
8
+ Execution Generator in App
9
9
 
10
10
  Options:
11
- -d, --debug 开启 Debug 模式,打印调试日志信息 (default: false)
12
- -c, --config <config> 生成器运行默认配置(JSON 字符串)
13
- --dist-tag <tag> 生成器使用特殊的 npm Tag 版本
14
- --registry 生成器运行过程中定制 npm Registry
15
- -h, --help 显示命令帮助
11
+ -d, --debug using debug mode to log something (default: false)
12
+ -c, --config <config> set default generator config(json string)
13
+ --dist-tag <tag> use specified tag version for its generator
14
+ --registry set npm registry url to run npm command
15
+ -h, --help show command help
16
16
  ```
17
17
 
18
- `modern new` 命令用于在已有项目中添加项目元素。
18
+ The `modern new` command is used to enable features to an existing project.
19
19
 
20
- 比如添加应用入口、启用启用一些可选功能如 Tailwind CSS、微前端开发模式等。
20
+ For example, add application entry, enable some optional features such as Tailwind CSS, micro frontend, etc.
21
21
 
22
22
  import CommandTip from '@site-docs/components/command-tip.md'
23
23
 
24
24
  <CommandTip />
25
25
 
26
- ### 添加入口
26
+ ### Add Entry
27
27
 
28
- 在应用工程中,执行 `new` 命令添加入口如下:
28
+ In the project, execute the `new` command to add entries as follows:
29
29
 
30
30
  ```bash
31
31
  $ npx modern new
@@ -35,9 +35,9 @@ $ npx modern new
35
35
  ? 是否需要调整默认配置? 否
36
36
  ```
37
37
 
38
- ### 启用启用可选功能
38
+ ### Enable Features
39
39
 
40
- 在应用工程中,执行 `new` 命令启用可选能力如下:
40
+ In the project, execute the `new` command to enable features as follows:
41
41
 
42
42
  ```bash
43
43
  $ npx modern new
@@ -52,8 +52,8 @@ $ npx modern new
52
52
  启用「Visual Testing (Storybook)」模式
53
53
  ```
54
54
 
55
- :::caution 注意
56
- `--config` 参数对应参数值需要使用 JSON 字符串。
55
+ :::caution
56
+ The `--config` parameter needs to use a JSON string.
57
57
 
58
- pnpm 暂不支持使用 JSON 字符串作为参数值,可使用 `npm new` 开启相关功能。【[相关 Issue](https://github.com/pnpm/pnpm/issues/3876)】
58
+ pnpm does not support the use of JSON strings as parameter values currently. Use `npm new` to turn on.【[Relate Issue](https://github.com/pnpm/pnpm/issues/3876)】
59
59
  :::
@@ -8,14 +8,14 @@ Usage: modern start [options]
8
8
  start server
9
9
 
10
10
  Options:
11
- -c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
12
- -h, --help 显示命令帮助
13
- --api-only 仅启动 API 接口服务
11
+ -c --config <config> configuration file path, which can be a relative path or an absolute path
12
+ -h, --help show command help
13
+ --api-only only start API service
14
14
  ```
15
15
 
16
- 通常使用 `modern start` 命令在生产环境下启用应用工程, 需要提前执行 [`build`](/docs/apis/app/commands/build) 命令构建出对应产物。
16
+ Usually use the `modern start` command to enable project start in the production environment, and you need to execute the [`build'](/docs/apis/app/commands/build) command in advance to build the product.
17
17
 
18
- 默认情况下,应用将会在 `localhost:8080` 启动,可以通过 `server.port` 修改 Server 端口号:
18
+ By default, the project will start in `localhost:8080`, you can modify the Server port number with `server.port`:
19
19
 
20
20
  ```js
21
21
  export default defineConfig({
@@ -6,14 +6,14 @@ sidebar_position: 3
6
6
  Usage: modern test [options]
7
7
 
8
8
  Options:
9
- -h, --help 显示命令帮助
9
+ -h, --help show command help
10
10
  ```
11
11
 
12
- :::caution 注意
13
- `modern test` 命令需要先通过 [`new`](/docs/apis/app/commands/new) 命令启用「单元测试 / 集成测试」功能
12
+ :::caution
13
+ `modern test` command need to execute the `new` command in advance to enable the `unit test/integration test`.
14
14
  :::
15
15
 
16
- `modern test` 命令会自动运行项目下的测试用例,效果如下:
16
+ `modern test` command will automatically run the test cases, the effect is as follows:
17
17
 
18
18
  ```bash
19
19
  $ npx modern test
@@ -28,7 +28,7 @@ Time: 0.994 s, estimated 1 s
28
28
  ```
29
29
 
30
30
  :::info
31
- `src` `api` 目录下面 `*.test.(js|ts)` 都会默认识别为测试用例。
31
+ files match `*.test.(js|ts)` in `api/` or `src/` will be recognized as test cases by default。
32
32
  :::
33
33
 
34
34
  import CommandTip from '@site-docs/components/command-tip.md'
@@ -5,19 +5,17 @@ sidebar_position: 8
5
5
  ```
6
6
  Usage: modern upgrade [options]
7
7
 
8
- 升级 Modern.js 到最新版本
8
+ upgrade Modern.js to latest version.
9
9
 
10
10
  Options:
11
- --registry <registry> 定制 npm registry (default: "")
12
- -d,--debug 开启 Debug 模式,打印调试日志信息 (default: false)
13
- --cwd <cwd> 项目路径 (default: "")
14
- -h, --help display help for command
11
+ --registry <registry> specify npm registry (default: "")
12
+ -d,--debug using debug mode to log something (default: false)
13
+ --cwd <cwd> app directory (default: "")
14
+ -h, --help show command help
15
15
  ```
16
16
 
17
- `modern upgrade` 命令,用于升级项目 Modern.js 相关依赖至最新版本。
18
-
19
- 在项目根目录下执行命令 `npx modern upgrade`,会默认将当前执行命令项目的 `package.json` 中的 Modern.js 相关依赖更新至最新版本。
17
+ Execute the command `npx modern upgrade` in the project, by default, dependencies in the `package.json` are updated to the latest version.
20
18
 
21
19
  :::info
22
- 命令在 `@modern-js/app-tools` 版本 >= 1.17.0 提供,之前版本可使用 `npx @modern-js/upgrade` 进行升级。
20
+ the command is available in `@modern-js/app-tools` version >= 1.17.0, previous versions can be upgraded with `npx @modern-js/upgrade`.
23
21
  :::
@@ -1,5 +1,5 @@
1
1
  {
2
- "label": "文件约定",
2
+ "label": "Convention",
3
3
  "position": 1,
4
4
  "link": {
5
5
  "type": "doc",
@@ -3,77 +3,52 @@ title: lambda/*.[tj]s
3
3
  sidebar_position: 1
4
4
  ---
5
5
 
6
- 声明 API 路由的文件,在 Modern.js 函数写法下;除了[某些约定文件](/docs/apis/app/hooks/api/framework/lambda#白名单)外,`api` 目录下的文件会被注册为接口的路由。
6
+ Declaring API routing in BFF framework mode. Except [some files](/docs/apis/app/hooks/api/framework/lambda#allow-list),files in `api/` are registered as routes.
7
7
 
8
8
  :::info
9
- 使用 `api` 目录需要开启 BFF 功能,需要在项目下执行 new 命令启用「BFF」功能。
9
+ use `api/` need execute new command to enable the 「BFF」 feature.
10
+ :::
10
11
 
11
- 该文件支持使用 `js` 或 `ts` 语言,但必须使用 `esm` 语法导出函数。
12
+ :::tip
13
+ this file supports the use `js` or `ts`, but the functions must be exported using the ESM syntax.
12
14
  :::
13
15
 
14
- ## 路由规则
16
+ ## Routing Rule
15
17
 
16
- ### 默认路由
18
+ ### Default Route
17
19
 
18
- 路由系统会将以 `index` 命名的文件会被映射到上一层目录。
20
+ The files named `index` will be upper level routing:
19
21
 
20
22
  * `api/lambda/index.ts` -> `$BASENAME/`
21
23
  * `api/lambda/user/index.ts` -> `$BASENAME/user`
22
24
 
23
- ### 嵌套路由
25
+ ### Multi Level Route
24
26
 
25
- 路由系统也支持解析嵌套的文件,如果创建嵌套文件夹结构,文件仍会以相同方式自动解析路由。
27
+ The routing system also supports parsing multiple levels of files. and if you create a folder, the files will still be automatically parsed in the same way.
26
28
 
27
29
  * `api/lambda/hello.ts` -> `$BASENAME/hello`
28
30
  * `api/lambda/user/list.ts` -> `$BASENAME/user/list`
29
31
 
30
- ### 动态路由
32
+ ### Dynamic Route
31
33
 
32
- 同样的,你可以通过创建带有 `[xxx]` 的文件夹或者文件来支持动态的命名路由参数。
34
+ Dynamic named routing parameters can be supported by creating folders or files with `[xxx]`.
33
35
 
34
36
  * `api/lambda/user/[username]/info.ts` -> `$BASENAME/user/:username/info`
35
37
  * `api/lambda/user/[username]/delete.ts` -> `$BASENAME/user/:username/delete`
36
38
  * `api/lambda/article/[id]/info.ts` -> `$BASENAME/article/:id/info`
37
39
 
38
- 其中的 `$BASENAME` 可以在 `modern.config.js` 中进行配置,默认值为 `/api`。
39
-
40
- ### 白名单
41
-
42
- 默认 `api` 目录下所有文件都会当作 BFF 函数文件去解析,但同样我们也设置了白名单,这些文件不被被解析:
43
-
44
- * 命名以 `_` 开头的文件。例如:`_utils.ts`。
45
- * 命名以 `_` 开头的文件夹下所有文件。例如:`_utils/index.ts`、`_utils/cp.ts`。
46
- * 测试文件。例如:`foo.test.ts`。
47
- * TypeScript 类型文件。例如:`hello.d.ts`。
48
- * `node_module` 下的文件。
49
-
50
- ## 函数定义
51
-
52
- 除了上面的路由规则之外,代码中函数定义与导出也有相应的约定。
40
+ the `$BASENAME` can be configured in `modern.config.js`,the default value is `/api`。
53
41
 
54
- * 首先命名导出时,导出函数的名字为对应接口接受的 HTTP Method。
42
+ ### Allow List
55
43
 
56
- 即:
44
+ By default, all files in the `api/` will be parsed as BFF function. but we also set a allow list, and these files will not be parsed:
57
45
 
58
- ```ts
59
- export const get = async () => {
60
- return {
61
- name: 'Modern.js',
62
- desc: '现代 web 工程方案',
63
- };
64
- };
65
- ```
46
+ * file name start with `_`, for example: `_utils.ts`.
47
+ * files in directory that name start with `_`, for example:`_utils/index.ts`、`_utils/cp.ts`.
48
+ * test files, for example:`foo.test.ts`.
49
+ * TypeScript define files, for example:`hello.d.ts`.
50
+ * files in `node_module`.
66
51
 
67
- 这样导出函数,则会得到一个 `POST` 接口。
52
+ ## Define Function
68
53
 
69
- 应用工程中支持了 9 Method 定义,即:`GET`、`POST`、`PUT`、`DELETE`、`CONNECT`、`TRACE`、`PATCH`、`OPTION`、`HEAD`,即可以用这些 Method 作为函数导出的名字。
70
-
71
- 名字是大小不敏感的,就是说,如果是 `GET`,写成 `get`、`Get`、`GEt`、`GET`,都可以准确识别。而默认导出,即 `export default xxx` 则会被映射为 `Get`。
72
-
73
- 因为 `delete` 是 `javascript` 中的关键字,可以使用 `del` 或者 `DELETE` 代替。
74
-
75
- 可以在一个文件中定义多个不同 Method 的函数,但如果定义多个相同 Method 的函数,则只有第一个会生效。
76
-
77
- :::info
78
- 需要注意的是,定义的函数都应该是异步的,这个与函数调用时类型有关,这个后面会提到。
79
- :::
54
+ the same as [Define Function](/docs/apis/app/hooks/api/functions/api#define-function).
@@ -3,48 +3,76 @@ title: "**/*.[tj]s"
3
3
  sidebar_position: 1
4
4
  ---
5
5
 
6
- 声明 API 路由的文件,在 Modern.js 函数写法下;除了[某些约定文件](/docs/apis/app/hooks/api/functions/api)外,`api` 目录下的文件会被注册为接口的路由。
6
+ Declaring API routing in BFF function mode. Except [some files](/docs/apis/app/hooks/api/functions/api#allow-list),files in `api/` are registered as routes.
7
7
 
8
8
  :::info
9
- 使用 `api` 目录需要开启 BFF 功能,需要在项目下执行 new 命令启用「BFF」功能。
9
+ use `api/` need execute new command to enable the 「BFF」 feature.
10
+ :::
10
11
 
11
- 该文件支持使用 `js` 或 `ts` 语言,但必须使用 `esm` 语法导出函数。
12
+ :::tip
13
+ this file supports the use `js` or `ts`, but the functions must be exported using the ESM syntax.
12
14
  :::
13
15
 
14
- ## 该文件约定路由如下:
16
+ ## Routing Rule
15
17
 
16
- ### 默认路由
18
+ ### Default Route
17
19
 
18
- 路由系统会将以 `index` 命名的文件会被映射到上一层目录。
20
+ The files named `index` will be upper level routing:
19
21
 
20
22
  * `api/index.ts` -> `$BASENAME/`
21
23
  * `api/user/index.ts` -> `$BASENAME/user`
22
24
 
23
- ### 嵌套路由
25
+ ### Multi Level Route
24
26
 
25
- 路由系统也支持解析嵌套的文件,如果创建嵌套文件夹结构,文件仍会以相同方式自动解析路由。
27
+ The routing system also supports parsing multiple levels of files. and if you create a folder, the files will still be automatically parsed in the same way.
26
28
 
27
29
  * `api/hello.ts` -> `$BASENAME/hello`
28
30
  * `api/user/list.ts` -> `$BASENAME/user/list`
29
31
 
30
- ### 动态路由
32
+ ### Dynamic Route
31
33
 
32
- 同样的,你可以通过创建带有 `[xxx]` 的文件夹或者文件来支持动态的命名路由参数。
34
+ Dynamic named routing parameters can be supported by creating folders or files with `[xxx]`.
33
35
 
34
36
  * `api/user/[username]/info.ts` -> `$BASENAME/user/:username/info`
35
37
  * `api/user/[username]/delete.ts` -> `$BASENAME/user/:username/delete`
36
38
  * `api/article/[id]/info.ts` -> `$BASENAME/article/:id/info`
37
39
 
38
- 其中的 `$BASENAME` 可以在 `modern.config.js` 中进行配置,默认值为 `/api`。
40
+ the `$BASENAME` can be configured in `modern.config.js`,the default value is `/api`。
41
+
42
+ ### Allow List
43
+
44
+ By default, all files in the `api/` will be parsed as BFF function. but we also set a allow list, and these files will not be parsed:
45
+
46
+ * file name start with `_`, for example: `_utils.ts`.
47
+ * files in directory that name start with `_`, for example:`_utils/index.ts`、`_utils/cp.ts`.
48
+ * test files, for example:`foo.test.ts`.
49
+ * TypeScript define files, for example:`hello.d.ts`.
50
+ * files in `node_module`.
51
+
52
+ ## Define Function
39
53
 
40
- ### 白名单
54
+ In addition to the above routing rules, the function definition and export in the code also have conventions.
41
55
 
42
- 默认 `api` 目录下所有文件都会当作 BFF 函数文件去解析,但同样我们也设置了白名单,这些文件不被被解析:
56
+ function need named exports,and the name of the exported function is the HTTP Method:
43
57
 
44
- * 命名以 `_` 开头的文件。例如:`_utils.ts`。
45
- * 命名以 `_` 开头的文件夹下所有文件。例如:`_utils/index.ts`、`_utils/cp.ts`。
46
- * 测试文件。例如:`foo.test.ts`。
47
- * TypeScript 类型文件。例如:`hello.d.ts`。
48
- * `node_module` 下的文件。
58
+ ```ts
59
+ export const get = async () => {
60
+ return {
61
+ name: 'Modern.js',
62
+ desc: 'Modern web Solutions',
63
+ };
64
+ };
65
+ ```
49
66
 
67
+ Export the function like above will generate a `POST` interface.
50
68
 
69
+ App support 9 Method definitions: `GET`、`POST`、`PUT`、`DELETE`、`CONNECT`、`TRACE`、`PATCH`、`OPTION`、`HEAD`. so App can use these name as function export nane.
70
+
71
+ The name is insensitive, whaterver `get`、`Get`、`GEt`、`GET`, can be accurately identified. And default export, `export default xxx` will be `Get` method.
72
+
73
+ because `delete` is a keyword in JavaScript, use `del` or `DELETE` instead.
74
+
75
+ Multiple functions of different Methods can be defined in one file, but if multiple functions of the same Method are defined, only the first can work.
76
+
77
+ :::info
78
+ It should be noted that the defined functions should be asynchronous, which is related to the type when the function is called.
@@ -3,10 +3,10 @@ title: _app.[tj]s
3
3
  sidebar_position: 3
4
4
  ---
5
5
 
6
- 在函数写法下,该文件可以为 [BFF 函数](/docs/apis/app/hooks/api/functions/api)添加前置中间件。
6
+ in BFF function mode,this file can add middleware before [BFF 函数](/docs/apis/app/hooks/api/functions/api).
7
7
 
8
8
  :::note
9
- 具体示例请参考 [hook](/docs/apis/app/runtime/bff/hook)
9
+ For detail, see [hook](/docs/apis/app/runtime/bff/hook)
10
10
  :::
11
11
 
12
12
 
@@ -3,8 +3,8 @@ title: "**/_*.[tj]s, _*/**"
3
3
  sidebar_position: 2
4
4
  ---
5
5
 
6
- Modern.js 函数写法下,这些文件不会注册为路由;你可以在这种目录或文件下放任意项目中需要的代码,文件等。
6
+ under BFF function mode, these files are not registered as routes.
7
+
8
+ Any files that not routes, but required in the project can be named in this way.
9
+
7
10
 
8
- :::info
9
- 使用 `api` 目录的开启 BFF 功能,需要在项目下执行 new 命令启用「BFF」功能。
10
- :::
@@ -3,10 +3,8 @@ title: test.[tj]s
3
3
  sidebar_position: 2
4
4
  ---
5
5
 
6
- 应用项目 BFF 测试文件。
7
-
8
- 应用项目支持在项目 API 目录下创建后缀为 `.test.[tj]sx?` 文件进行编写测试用例。
6
+ App's BFF test file,support for writing test cases in the `api/` directory which file with suffix `.test.[tj]s`.
9
7
 
10
8
  :::info
11
- 使用单元测试、集成测试需要提前在项目下执行 new 命令启用「单元测试 / 集成测试」功能。
9
+ To use unit test and integration test, you need to execute the `new` command in advance to enable the `unit test/integration test`.
12
10
  :::
@@ -3,8 +3,6 @@ title: html/
3
3
  sidebar_position: 1
4
4
  ---
5
5
 
6
- 应用工程方案自定义 html 片段文件。
6
+ The `config/html` directory allows you to inject custom html snippets in different places in the default html template.
7
7
 
8
- 通过 `config/html` 目录可以在内部默认 html 模板的不同位置注入自定义的 html 片段。
9
-
10
- 具体使用方式请参考: [自定义 HTML](/docs/guides/basic-features/html)
8
+ For detail, see [HTML](/docs/guides/basic-features/html).
@@ -3,15 +3,13 @@ title: icon.png
3
3
  sidebar_position: 2
4
4
  ---
5
5
 
6
- 应用工程方案 App Icon 文件。
7
-
8
- 项目根目录下 `config/icon.png` 时,可以在构建时在 html 页面注入 app icon 信息, 如下:
6
+ When `config/icon.png` exist, it can inject app icon information into the html page at build time:
9
7
 
10
8
  ```
11
- ./config
9
+ .config
12
10
  └── icon.png
13
11
  ```
14
12
 
15
- 最终 html 中会注入 app icon `link` 标签, 如下:
13
+ the app icon `link` meta will be injected into the html, as follows:
16
14
 
17
15
  ![app-icon](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/api/app-icon.png)
@@ -3,10 +3,4 @@ title: mock/
3
3
  sidebar_position: 5
4
4
  ---
5
5
 
6
- 应用工程方案本地调试 Mock 数据文件。
7
-
8
- 项目根目录下存在 `config/mock/index.js` 时,在本地开发调试环节自动启用快速 Mock 数据的功能。
9
-
10
- :::caution 注意
11
- 为避免 Mock API 不生效, 请注意不要与配置 [tools.devServer.proxy](/docs/configure/app/tools/dev-server) 的 API 有冲突。
12
- :::
6
+ when `config/mock/index.js` exist,Modernjs auto start the Mock service in the development.