@modern-js/main-doc 2.21.1 → 2.22.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +18 -0
- package/docs/en/apis/app/commands.mdx +5 -5
- package/docs/en/apis/app/hooks/api/api.mdx +80 -0
- package/docs/en/apis/app/hooks/api/app.mdx +12 -0
- package/docs/en/apis/app/hooks/api/lambda.mdx +57 -0
- package/docs/en/apis/app/hooks/api/test.mdx +1 -1
- package/docs/en/apis/app/hooks/config/html.mdx +2 -2
- package/docs/en/apis/app/hooks/config/icon.mdx +19 -19
- package/docs/en/apis/app/hooks/config/mock.mdx +1 -1
- package/docs/en/apis/app/hooks/config/public.mdx +10 -10
- package/docs/en/apis/app/hooks/config/storybook.mdx +3 -3
- package/docs/en/apis/app/hooks/config/upload.mdx +13 -13
- package/docs/en/apis/app/hooks/modern-config.mdx +4 -4
- package/docs/en/apis/app/hooks/server/index_.mdx +2 -9
- package/docs/en/apis/app/hooks/server/test.mdx +5 -2
- package/docs/en/apis/app/hooks/shared.mdx +1 -1
- package/docs/en/apis/app/hooks/src/app.mdx +17 -27
- package/docs/en/apis/app/hooks/src/index_.mdx +6 -6
- package/docs/en/apis/app/hooks/src/pages.mdx +41 -37
- package/docs/en/apis/app/hooks/src/routes.mdx +16 -36
- package/docs/en/apis/app/hooks/src/server.mdx +1 -1
- package/docs/en/apis/app/hooks/src/stories.mdx +6 -3
- package/docs/en/apis/app/hooks/src/test.mdx +4 -3
- package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +5 -1
- package/docs/en/apis/app/runtime/web-server/hook.mdx +2 -2
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +2 -2
- package/docs/en/components/init-app.mdx +3 -3
- package/docs/en/components/init-rspack-app.mdx +4 -4
- package/docs/en/components/language-config.mdx +9 -0
- package/docs/en/components/package-manager.mdx +11 -0
- package/docs/en/components/ua-polyfill.mdx +2 -2
- package/docs/en/configure/app/source/config-dir.mdx +1 -1
- package/docs/en/configure/app/source/design-system.mdx +67 -67
- package/docs/en/configure/app/source/disable-default-entries.mdx +6 -5
- package/docs/en/configure/app/source/disable-entry-dirs.mdx +5 -5
- package/docs/en/configure/app/source/enable-async-entry.mdx +9 -9
- package/docs/en/configure/app/source/entries-dir.mdx +3 -3
- package/docs/en/configure/app/source/entries.mdx +21 -19
- package/docs/en/configure/app/tools/swc.mdx +2 -2
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -2
- package/docs/en/guides/advanced-features/bff/function.mdx +4 -4
- package/docs/en/guides/advanced-features/bff/type.mdx +5 -5
- package/docs/en/guides/advanced-features/rspack-start.mdx +6 -6
- package/docs/en/guides/advanced-features/ssg.mdx +2 -2
- package/docs/en/guides/advanced-features/testing.mdx +2 -2
- package/docs/en/guides/advanced-features/web-server.mdx +2 -2
- package/docs/en/guides/basic-features/css.mdx +2 -2
- package/docs/en/guides/basic-features/mock.mdx +1 -1
- package/docs/en/guides/basic-features/routes.mdx +11 -7
- package/docs/en/guides/concept/entries.mdx +3 -3
- package/docs/en/guides/topic-detail/generator/create/_category_.json +4 -0
- package/docs/en/guides/topic-detail/generator/create/config.mdx +75 -0
- package/docs/en/guides/topic-detail/generator/create/option.md +151 -0
- package/docs/en/guides/topic-detail/generator/create/use.mdx +66 -0
- package/docs/en/guides/topic-detail/generator/new/_category_.json +4 -0
- package/docs/en/guides/topic-detail/generator/new/config.md +155 -0
- package/docs/en/guides/topic-detail/generator/new/option.md +67 -0
- package/docs/en/guides/topic-detail/generator/new/use.md +95 -0
- package/docs/en/guides/topic-detail/generator/plugin/_category_.json +2 -2
- package/docs/en/guides/topic-detail/generator/plugin/api/_category_.json +1 -1
- package/docs/en/guides/topic-detail/generator/plugin/api/afterForged.md +49 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/context.md +184 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/input.md +124 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/onForged.md +310 -0
- package/docs/en/guides/topic-detail/generator/plugin/category.md +88 -0
- package/docs/en/guides/topic-detail/generator/plugin/context.md +104 -0
- package/docs/en/guides/topic-detail/generator/plugin/structure.md +106 -0
- package/docs/en/guides/topic-detail/generator/plugin/use.md +33 -0
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +8 -8
- package/docs/en/tutorials/first-app/c03-css.mdx +2 -2
- package/docs/en/tutorials/first-app/c08-entries.mdx +3 -3
- package/docs/zh/apis/app/commands.mdx +3 -3
- package/docs/zh/apis/app/hooks/api/{functions/api.mdx → api.mdx} +4 -4
- package/docs/zh/apis/app/hooks/api/app.mdx +12 -0
- package/docs/zh/apis/app/hooks/api/{framework/lambda.mdx → lambda.mdx} +5 -5
- package/docs/zh/apis/app/hooks/api/test.mdx +3 -3
- package/docs/zh/apis/app/hooks/config/icon.mdx +15 -15
- package/docs/zh/apis/app/hooks/config/mock.mdx +1 -1
- package/docs/zh/apis/app/hooks/config/public.mdx +3 -3
- package/docs/zh/apis/app/hooks/config/upload.mdx +1 -1
- package/docs/zh/apis/app/hooks/modern-config.mdx +3 -3
- package/docs/zh/apis/app/hooks/server/index_.mdx +1 -6
- package/docs/zh/apis/app/hooks/shared.mdx +1 -1
- package/docs/zh/apis/app/hooks/src/app.mdx +15 -25
- package/docs/zh/apis/app/hooks/src/index_.mdx +6 -6
- package/docs/zh/apis/app/hooks/src/pages.mdx +7 -3
- package/docs/zh/apis/app/hooks/src/routes.mdx +4 -4
- package/docs/zh/apis/app/hooks/src/stories.mdx +1 -1
- package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +5 -1
- package/docs/zh/components/language-config.mdx +9 -0
- package/docs/zh/components/package-manager.mdx +11 -0
- package/docs/zh/components/ua-polyfill.mdx +1 -1
- package/docs/zh/configure/app/source/design-system.mdx +3 -4
- package/docs/zh/configure/app/source/enable-async-entry.mdx +2 -5
- package/docs/zh/configure/app/source/entries.mdx +2 -2
- package/docs/zh/configure/app/tools/swc.mdx +2 -2
- package/docs/zh/guides/advanced-features/rspack-start.mdx +6 -6
- package/docs/zh/guides/advanced-features/ssg.mdx +1 -1
- package/docs/zh/guides/advanced-features/testing.mdx +2 -2
- package/docs/zh/guides/advanced-features/web-server.mdx +1 -1
- package/docs/zh/guides/basic-features/css.mdx +1 -1
- package/docs/zh/guides/basic-features/mock.mdx +1 -1
- package/docs/zh/guides/basic-features/routes.mdx +7 -4
- package/docs/zh/guides/concept/entries.mdx +3 -3
- package/docs/zh/guides/topic-detail/generator/create/_category_.json +4 -0
- package/docs/zh/guides/topic-detail/generator/create/config.mdx +76 -0
- package/docs/zh/guides/topic-detail/generator/create/option.md +151 -0
- package/docs/zh/guides/topic-detail/generator/create/use.mdx +66 -0
- package/docs/zh/guides/topic-detail/generator/new/_category_.json +4 -0
- package/docs/zh/guides/topic-detail/generator/new/config.md +153 -0
- package/docs/zh/guides/topic-detail/generator/new/option.md +67 -0
- package/docs/zh/guides/topic-detail/generator/new/use.md +94 -0
- package/docs/zh/guides/topic-detail/generator/plugin/_category_.json +2 -2
- package/docs/zh/guides/topic-detail/generator/plugin/api/_category_.json +1 -1
- package/docs/zh/guides/topic-detail/generator/plugin/api/afterForged.md +50 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/context.md +184 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/input.md +124 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/onForged.md +310 -0
- package/docs/zh/guides/topic-detail/generator/plugin/category.md +93 -0
- package/docs/zh/guides/topic-detail/generator/plugin/context.md +105 -0
- package/docs/zh/guides/topic-detail/generator/plugin/structure.md +106 -0
- package/docs/zh/guides/topic-detail/generator/plugin/use.md +33 -0
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +4 -4
- package/docs/zh/guides/topic-detail/model/test-model.mdx +1 -1
- package/docs/zh/tutorials/first-app/c03-css.mdx +1 -1
- package/docs/zh/tutorials/first-app/c08-entries.mdx +1 -1
- package/package.json +5 -5
- package/docs/en/apis/app/hooks/api/framework/_category_.json +0 -4
- package/docs/en/apis/app/hooks/api/framework/lambda.mdx +0 -57
- package/docs/en/apis/app/hooks/api/functions/_category_.json +0 -4
- package/docs/en/apis/app/hooks/api/functions/api.mdx +0 -81
- package/docs/en/apis/app/hooks/api/functions/app.mdx +0 -12
- package/docs/en/apis/app/hooks/api/functions/common.mdx +0 -9
- package/docs/en/guides/topic-detail/generator/codesmith/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/codesmith/api/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/codesmith/api/app.mdx +0 -152
- package/docs/en/guides/topic-detail/generator/codesmith/api/ejs.mdx +0 -56
- package/docs/en/guides/topic-detail/generator/codesmith/api/fs.mdx +0 -54
- package/docs/en/guides/topic-detail/generator/codesmith/api/git.mdx +0 -50
- package/docs/en/guides/topic-detail/generator/codesmith/api/handlebars.mdx +0 -57
- package/docs/en/guides/topic-detail/generator/codesmith/api/json.mdx +0 -56
- package/docs/en/guides/topic-detail/generator/codesmith/api/npm.mdx +0 -48
- package/docs/en/guides/topic-detail/generator/codesmith/develop.mdx +0 -53
- package/docs/en/guides/topic-detail/generator/codesmith/introduce.mdx +0 -47
- package/docs/en/guides/topic-detail/generator/codesmith/run-in-js.mdx +0 -47
- package/docs/en/guides/topic-detail/generator/codesmith/structure.mdx +0 -89
- package/docs/en/guides/topic-detail/generator/config/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/config/app.mdx +0 -82
- package/docs/en/guides/topic-detail/generator/config/common.mdx +0 -100
- package/docs/en/guides/topic-detail/generator/config/module.mdx +0 -42
- package/docs/en/guides/topic-detail/generator/config/monorepo.mdx +0 -28
- package/docs/en/guides/topic-detail/generator/plugin/abstract.mdx +0 -23
- package/docs/en/guides/topic-detail/generator/plugin/api/file/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addFile.mdx +0 -52
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +0 -26
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addManyFile.mdx +0 -58
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addPartial.mdx +0 -26
- package/docs/en/guides/topic-detail/generator/plugin/api/file/introduce.mdx +0 -39
- package/docs/en/guides/topic-detail/generator/plugin/api/file/rmDir.mdx +0 -24
- package/docs/en/guides/topic-detail/generator/plugin/api/file/rmFile.mdx +0 -24
- package/docs/en/guides/topic-detail/generator/plugin/api/file/updateJSONFile.mdx +0 -54
- package/docs/en/guides/topic-detail/generator/plugin/api/file/updateModernConfig.mdx +0 -27
- package/docs/en/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.mdx +0 -33
- package/docs/en/guides/topic-detail/generator/plugin/api/git/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/git/gitAddAndCommit.mdx +0 -20
- package/docs/en/guides/topic-detail/generator/plugin/api/git/initGitRepo.mdx +0 -16
- package/docs/en/guides/topic-detail/generator/plugin/api/git/isInGitRepo.mdx +0 -16
- package/docs/en/guides/topic-detail/generator/plugin/api/hook/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/hook/afterForged.mdx +0 -35
- package/docs/en/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +0 -35
- package/docs/en/guides/topic-detail/generator/plugin/api/info/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/info/isFileExit.mdx +0 -22
- package/docs/en/guides/topic-detail/generator/plugin/api/info/locale.mdx +0 -17
- package/docs/en/guides/topic-detail/generator/plugin/api/info/readDir.mdx +0 -22
- package/docs/en/guides/topic-detail/generator/plugin/api/input/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/input/addInputAfter.mdx +0 -55
- package/docs/en/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +0 -55
- package/docs/en/guides/topic-detail/generator/plugin/api/input/setInput.mdx +0 -43
- package/docs/en/guides/topic-detail/generator/plugin/api/input/setInputValue.mdx +0 -31
- package/docs/en/guides/topic-detail/generator/plugin/api/input/type.mdx +0 -65
- package/docs/en/guides/topic-detail/generator/plugin/api/introduce.mdx +0 -90
- package/docs/en/guides/topic-detail/generator/plugin/api/new/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/new/createElement.mdx +0 -33
- package/docs/en/guides/topic-detail/generator/plugin/api/new/createSubProject.mdx +0 -35
- package/docs/en/guides/topic-detail/generator/plugin/api/new/enableFunc.mdx +0 -44
- package/docs/en/guides/topic-detail/generator/plugin/api/new/introduce.mdx +0 -15
- package/docs/en/guides/topic-detail/generator/plugin/api/npm/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/npm/install.mdx +0 -18
- package/docs/en/guides/topic-detail/generator/plugin/develop.mdx +0 -125
- package/docs/en/guides/topic-detail/generator/plugin/use.mdx +0 -61
- package/docs/en/guides/topic-detail/generator/project.mdx +0 -118
- package/docs/zh/apis/app/hooks/api/framework/_category_.json +0 -4
- package/docs/zh/apis/app/hooks/api/functions/_category_.json +0 -4
- package/docs/zh/apis/app/hooks/api/functions/app.mdx +0 -12
- package/docs/zh/apis/app/hooks/api/functions/common.mdx +0 -9
- package/docs/zh/guides/topic-detail/generator/codesmith/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/codesmith/api/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/codesmith/api/app.mdx +0 -152
- package/docs/zh/guides/topic-detail/generator/codesmith/api/ejs.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/codesmith/api/fs.mdx +0 -54
- package/docs/zh/guides/topic-detail/generator/codesmith/api/git.mdx +0 -49
- package/docs/zh/guides/topic-detail/generator/codesmith/api/handlebars.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/codesmith/api/json.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/codesmith/api/npm.mdx +0 -47
- package/docs/zh/guides/topic-detail/generator/codesmith/develop.mdx +0 -53
- package/docs/zh/guides/topic-detail/generator/codesmith/introduce.mdx +0 -59
- package/docs/zh/guides/topic-detail/generator/codesmith/run-in-js.mdx +0 -47
- package/docs/zh/guides/topic-detail/generator/codesmith/structure.mdx +0 -89
- package/docs/zh/guides/topic-detail/generator/config/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/config/app.mdx +0 -82
- package/docs/zh/guides/topic-detail/generator/config/common.mdx +0 -100
- package/docs/zh/guides/topic-detail/generator/config/module.mdx +0 -42
- package/docs/zh/guides/topic-detail/generator/config/monorepo.mdx +0 -28
- package/docs/zh/guides/topic-detail/generator/plugin/abstract.mdx +0 -23
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addFile.mdx +0 -52
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +0 -26
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addManyFile.mdx +0 -55
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addPartial.mdx +0 -26
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/introduce.mdx +0 -39
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/rmDir.mdx +0 -24
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/rmFile.mdx +0 -24
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateJSONFile.mdx +0 -54
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateModernConfig.mdx +0 -27
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.mdx +0 -33
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/gitAddAndCommit.mdx +0 -20
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/initGitRepo.mdx +0 -16
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/isInGitRepo.mdx +0 -16
- package/docs/zh/guides/topic-detail/generator/plugin/api/hook/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/hook/afterForged.mdx +0 -35
- package/docs/zh/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +0 -35
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/isFileExit.mdx +0 -22
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/locale.mdx +0 -17
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/readDir.mdx +0 -22
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/addInputAfter.mdx +0 -57
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/setInput.mdx +0 -43
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/setInputValue.mdx +0 -29
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/type.mdx +0 -65
- package/docs/zh/guides/topic-detail/generator/plugin/api/introduce.mdx +0 -92
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/createElement.mdx +0 -33
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/createSubProject.mdx +0 -35
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/enableFunc.mdx +0 -44
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/introduce.mdx +0 -15
- package/docs/zh/guides/topic-detail/generator/plugin/api/npm/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/npm/install.mdx +0 -16
- package/docs/zh/guides/topic-detail/generator/plugin/develop.mdx +0 -125
- package/docs/zh/guides/topic-detail/generator/plugin/use.mdx +0 -61
- package/docs/zh/guides/topic-detail/generator/project.mdx +0 -118
@@ -6,7 +6,7 @@ title: Frameworks
|
|
6
6
|
|
7
7
|
Modern.js's BFF supports different runtime frameworks, currently Modern.js's BFF supports two runtime frameworks[Express.js](https://expressjs.com/) 和 [Koa.js](https://koajs.com/).
|
8
8
|
|
9
|
-
## Function
|
9
|
+
## Function Mode
|
10
10
|
|
11
11
|
Under the function writing, only the middleware writing method of various runtime frameworks is different, and other implementations are basically the same. Take Express as an example to introduce how to write a middleware by hand in the `api/_ app.ts` and add permission verification:
|
12
12
|
|
@@ -96,7 +96,7 @@ Refresh the page and you can see that `/api/hello` was accessed successfully:
|
|
96
96
|
|
97
97
|
The above code simulates the way to add middleware to the `/api/_app.ts` to achieve an easy login function. Also, other functions can be implemented in this hook file to extend BFF Server.
|
98
98
|
|
99
|
-
## Framework
|
99
|
+
## Framework Mode
|
100
100
|
|
101
101
|
Under the framework writing, Modern.js does not collect middleware in the `api/_app.ts`, and the running process is controlled by the plugin itself.
|
102
102
|
|
@@ -51,10 +51,10 @@ Execute `pnpm run dev`, then open `http://localhost:8080/` to see that the page
|
|
51
51
|
|
52
52
|
In Modern.js, the BFF function routing system is implemented based on the file system, and it is also a conventional routing system.
|
53
53
|
|
54
|
-
In **Function
|
54
|
+
In **Function Mode**, All files under `api/` will map to an interface. In **Framework Mode**, All files under `api/lambda` will map to an interface
|
55
55
|
|
56
56
|
:::note
|
57
|
-
Function
|
57
|
+
Function Mode & Framework Mode will introduce soon.
|
58
58
|
|
59
59
|
:::
|
60
60
|
|
@@ -69,14 +69,14 @@ Files named `index.[jt]s` are mapped to the previous directory.
|
|
69
69
|
- `api/index.ts` -> `{prefix}/`
|
70
70
|
- `api/user/index.ts` -> `{prefix}/user`
|
71
71
|
|
72
|
-
### Multi-layer
|
72
|
+
### Multi-layer Routing
|
73
73
|
|
74
74
|
Supports parsing nested files, if you create a nested folder structure, the files will still automatically parse routes in the same way.
|
75
75
|
|
76
76
|
- `api/hello.ts` -> `{prefix}/hello`
|
77
77
|
- `api/user/list.ts` -> `{prefix}/user/list`
|
78
78
|
|
79
|
-
### Dynamic
|
79
|
+
### Dynamic Routing
|
80
80
|
|
81
81
|
Create folders or files named with `[xxx]` to support dynamic named routing parameters.
|
82
82
|
|
@@ -1,19 +1,19 @@
|
|
1
1
|
---
|
2
2
|
sidebar_position: 2
|
3
|
-
title:
|
3
|
+
title: BFF Type
|
4
4
|
---
|
5
|
-
#
|
5
|
+
# BFF Type
|
6
6
|
|
7
7
|
Runtime framework support is also an important part of **BFF**. Modern.js supports extending BFF's runtime framework through plugins, and provides a series of built-in plugins, developers can directly use the conventions and ecology of the framework.
|
8
8
|
|
9
|
-
The plugin is compatible with most of the specifications of these frameworks, and each framework needs to provide two types of ways to extend the writing of BFF functions, namely **Function
|
9
|
+
The plugin is compatible with most of the specifications of these frameworks, and each framework needs to provide two types of ways to extend the writing of BFF functions, namely **Function Mode** and **Framework Mode**.
|
10
10
|
|
11
11
|
:::note
|
12
12
|
Whether the current `api/` directory structure is written as a framework is determined by the corresponding plugin, Modern.js don't care.
|
13
13
|
|
14
14
|
:::
|
15
15
|
|
16
|
-
## Function
|
16
|
+
## Function Mode
|
17
17
|
|
18
18
|
When the plugin considers that it is currently written as a function, it must support writing middleware in the `api/_ app.ts` to extend the BFF function.
|
19
19
|
|
@@ -32,7 +32,7 @@ The writing of middleware for different plugins is not the same, see [Runtime Fr
|
|
32
32
|
|
33
33
|
:::
|
34
34
|
|
35
|
-
## Framework
|
35
|
+
## Framework Mode
|
36
36
|
|
37
37
|
Framework writing is a way of using frame structure to extend BFF functions. Compared with function writing, although frame writing can use more frame structure and make the entire BFF Server clearer in complex scenarios, it is also more complex and requires more attention to the content at the framework level.
|
38
38
|
|
@@ -30,14 +30,14 @@ When using Rspack as the bundler, the following Features are temporarily unavail
|
|
30
30
|
|
31
31
|
:::
|
32
32
|
|
33
|
-
##
|
33
|
+
## Enable Rspack build
|
34
34
|
|
35
35
|
You can enable Rspack build by running `pnpm run new`:
|
36
36
|
|
37
37
|
```bash
|
38
38
|
$ pnpm run new
|
39
|
-
?
|
40
|
-
?
|
39
|
+
? Please select the operation you want: Enable features
|
40
|
+
? Please select the feature name: Enable Rspack Build
|
41
41
|
```
|
42
42
|
|
43
43
|
After executing the command, enable the Rspack build in `modern.config.ts`:
|
@@ -54,9 +54,9 @@ import appTools, { defineConfig } from '@modern-js/app-tools';
|
|
54
54
|
});
|
55
55
|
```
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
## Migrating configuration
|
58
|
+
|
59
|
+
After enabling Rspack building capability, further configuration migration is needed by referring to the [Configuration Differences](https://modernjs.dev/builder/en/guide/advanced/rspack-start.html#migrating-from-webpack-to-rspack).
|
60
60
|
|
61
61
|
## The relationship between Rspack and Modern.js versions
|
62
62
|
|
@@ -9,8 +9,8 @@ Static Site Generation is a solution for rendering complete static web pages at
|
|
9
9
|
First need to execute `pnpm run new` to enable the SSG features:
|
10
10
|
|
11
11
|
```bash
|
12
|
-
?
|
13
|
-
?
|
12
|
+
? Please select the operation you want: Enable features
|
13
|
+
? Please select the feature name: Enable SSG
|
14
14
|
```
|
15
15
|
|
16
16
|
After execute script, register SSG plugin in `modern.config.ts`:
|
@@ -9,8 +9,8 @@ Modern.js integrates the testing capabilities of [Jest](https://jestjs.io/) by d
|
|
9
9
|
First need to execute `pnpm run new` enable [unit test/integration test] features:
|
10
10
|
|
11
11
|
```
|
12
|
-
?
|
13
|
-
?
|
12
|
+
? Please select the operation you want: Enable features
|
13
|
+
? Please select the feature name: Enable Unit Test / Integration Test
|
14
14
|
```
|
15
15
|
|
16
16
|
After executing the above command, the `"test": "modern test"` command will be automatically generated in package.json.
|
@@ -27,8 +27,8 @@ Because the full web server cannot be controlled this way, and the extension log
|
|
27
27
|
You can execute the'pnpm run new 'command in the project root directory to enable the "Custom Web Serve" function:
|
28
28
|
|
29
29
|
```bash
|
30
|
-
?
|
31
|
-
? New "Custom Web Server" source code directory
|
30
|
+
? Please select the operation you want: Create Element
|
31
|
+
? Please select the type of element to create: New "Custom Web Server" source code directory
|
32
32
|
```
|
33
33
|
|
34
34
|
After executing the command, register the `@modern-js/plugin-server` plugin in `modern.config.ts`:
|
@@ -66,8 +66,8 @@ If you need to use other CSS-in-JS libraries such as [styled-jsx](https://www.np
|
|
66
66
|
Follow the steps below to make a selection:
|
67
67
|
|
68
68
|
```bash
|
69
|
-
?
|
70
|
-
?
|
69
|
+
? Please select the operation you want: Enable features
|
70
|
+
? Please select the feature name: Enable Tailwind CSS
|
71
71
|
```
|
72
72
|
|
73
73
|
Register the Tailwind plugin in `modern.config.ts`:
|
@@ -32,7 +32,7 @@ export default {
|
|
32
32
|
/* the default method is GET */
|
33
33
|
'/api/getExample': { id: 1 },
|
34
34
|
|
35
|
-
/* You can use custom functions to dynamically return data */
|
35
|
+
/* You can use custom functions to dynamically return data, req and res are both Node.js HTTP objects. */
|
36
36
|
'POST /api/addInfo': (req, res, next) => {
|
37
37
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
38
38
|
res.end('200');
|
@@ -182,7 +182,7 @@ Routes generated from file directories named with `[$]` will be treated as dynam
|
|
182
182
|
|
183
183
|
The `routes/user/[id$]/page.tsx` file will be converted to the `/user/:id?` route. All routes under `/user` will match this route, and the `id` parameter is optional. This route is usually used to distinguish between **creation** and **editing**.
|
184
184
|
|
185
|
-
In the component, you can use [useParams](/apis/app/runtime/router/router#useparams) to
|
185
|
+
In the component, you can use [useParams](/apis/app/runtime/router/router#useparams) to get the corresponding named parameter.
|
186
186
|
|
187
187
|
In the loader, params will be passed as the input parameter of the [loader function](/guides/basic-features/data-fetch#loader-function), and you can get the parameter value through `params.xxx`.
|
188
188
|
|
@@ -191,7 +191,7 @@ In the loader, params will be passed as the input parameter of the [loader funct
|
|
191
191
|
If you create a `$.tsx` file under the routes directory, it will be treated as the catch-all routing component. When there is no matching route, this component will be rendered.
|
192
192
|
|
193
193
|
:::note
|
194
|
-
`$.tsx` can be considered as a special `page` route component. When there is a `layout`
|
194
|
+
`$.tsx` can be considered as a special `page` route component. When there is a `layout.tsx` file in the current directory, `$.tsx` will be rendered as a child component of `layout`.
|
195
195
|
:::
|
196
196
|
|
197
197
|
For example, the following directory structure:
|
@@ -215,7 +215,7 @@ params['*']; // => 'aaa/bbb'
|
|
215
215
|
|
216
216
|
### No-path Layout
|
217
217
|
|
218
|
-
When the directory name starts with `__`, the
|
218
|
+
When the directory name starts with `__`, the directory name will not be converted to an actual route path. For example, the following file directory:
|
219
219
|
|
220
220
|
```bash
|
221
221
|
.
|
@@ -449,7 +449,7 @@ However, this also brings a problem: if the chunk corresponding to the route has
|
|
449
449
|
|
450
450
|
In this case, you can define a `Loading` component to display a custom `Loading` component before the static resources are loaded.
|
451
451
|
|
452
|
-
To further improve the user experience and reduce loading time, Modern.js supports defining the `prefetch` attribute on the Link component to preload static resources and data.
|
452
|
+
To further improve the user experience and reduce loading time, Modern.js supports defining the `prefetch` attribute on the Link component to preload static resources and data.
|
453
453
|
|
454
454
|
```tsx
|
455
455
|
<Link prefetch="intent" to="page">
|
@@ -461,6 +461,8 @@ To further improve the user experience and reduce loading time, Modern.js suppor
|
|
461
461
|
|
462
462
|
:::
|
463
463
|
|
464
|
+
The `prefetch` attribute has three optional values:
|
465
|
+
|
464
466
|
- `none`: default value, no prefetching, no additional behavior.
|
465
467
|
- `intent`: This is the value we recommend for most scenarios. When you hover over the Link, the corresponding chunk and data defined in the data loader will be loaded automatically. When you move the mouse away, the loading will be cancelled automatically. In our tests, even fast clicks can reduce loading time by about 200ms.
|
466
468
|
- `render`: The corresponding chunk and data defined in the Data Loader will be loaded when the Link component is rendered.
|
@@ -504,8 +506,6 @@ export default () => {
|
|
504
506
|
Modern.js provides a series of optimizations for resource loading and rendering for conventional routing by default, and provides out-of-the-box SSR capabilities. When using self-controlled routing, developers need to encapsulate these capabilities themselves. It is recommended to use conventional routing.
|
505
507
|
:::
|
506
508
|
|
507
|
-
When using self-controlled routing, if the developer turns off the [`runtime.router`](/configure/app/runtime/router) configuration and uses `react-router-dom` directly, they also need to wrap it according to the React Router documentation.
|
508
|
-
|
509
509
|
## Other
|
510
510
|
|
511
511
|
By default, Modern.js will enable the built-in routing scheme, which is React Router.
|
@@ -518,7 +518,9 @@ export default defineConfig({
|
|
518
518
|
});
|
519
519
|
```
|
520
520
|
|
521
|
-
Modern.js
|
521
|
+
As mentioned above, when the [`runtime.router`](/configure/app/runtime/router) configuration is enabled, Modern.js will export the API of React Router from the `@modern-js/runtime/router` namespace for developers to use, ensuring that developers and Modern.js are using the same code, and automatically wrapping the `Provider` component according to the router configuration. In addition, in this case, the code of React Router will be packed into the JS output.
|
522
|
+
|
523
|
+
If the project already has its own routing plan or does not need to use client-side routing, this feature can be disabled.
|
522
524
|
|
523
525
|
```js
|
524
526
|
export default defineConfig({
|
@@ -527,3 +529,5 @@ export default defineConfig({
|
|
527
529
|
},
|
528
530
|
});
|
529
531
|
```
|
532
|
+
|
533
|
+
As mentioned above, if the [`runtime.router`](/configure/app/runtime/router) configuration is disabled and `react-router-dom` is used directly for project routing management, the `Provider` needs to be wrapped according to the React Router documentation.
|
@@ -33,9 +33,9 @@ The project initialized by Modern.js is single-entry (SPA), and the project stru
|
|
33
33
|
Modern.js can easily switch from single entry to multiple entry. You can execute `pnpm run new` under the project to create entry through generator:
|
34
34
|
|
35
35
|
```bash
|
36
|
-
?
|
37
|
-
?
|
38
|
-
?
|
36
|
+
? Please select the operation you want: Create Element
|
37
|
+
? Please select the type of element to create: New "entry"
|
38
|
+
? Please fill in the entry name: new-entry
|
39
39
|
```
|
40
40
|
|
41
41
|
After execution, Modern.js will automatically generate a new entry directory, and you can see that the `src/` directory has the following structure:
|
@@ -0,0 +1,75 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 3
|
3
|
+
---
|
4
|
+
|
5
|
+
# Configuration Parameters
|
6
|
+
|
7
|
+
`@modern-js/create` provides the [--config](/guides/topic-detail/generator/create/option.html#-c,---config-<config>) parameter, which is used to specify the answers to interactive questions in advance during the execution process.
|
8
|
+
|
9
|
+
Here, we will introduce the fields and field values that can be configured in the `config` under different scenario.
|
10
|
+
|
11
|
+
## General Configuration
|
12
|
+
|
13
|
+
### solution
|
14
|
+
|
15
|
+
Question: Please select the type of project you want to create.
|
16
|
+
|
17
|
+
Options:
|
18
|
+
|
19
|
+
- Web App -- mwa
|
20
|
+
|
21
|
+
- Npm Module -- module
|
22
|
+
|
23
|
+
- Doc Site -- doc
|
24
|
+
|
25
|
+
- Monorepo -- monorepo
|
26
|
+
|
27
|
+
### scenes
|
28
|
+
|
29
|
+
Question: Please select the project scenario.
|
30
|
+
|
31
|
+
Options:
|
32
|
+
|
33
|
+
List of plugin keywords when using custom generator plugins.
|
34
|
+
|
35
|
+
## Web App
|
36
|
+
|
37
|
+
import LanguageConfig from '@site-docs-en/components/language-config';
|
38
|
+
|
39
|
+
<LanguageConfig />
|
40
|
+
|
41
|
+
import PackageManager from '@site-docs-en/components/package-manager';
|
42
|
+
|
43
|
+
<PackageManager />
|
44
|
+
|
45
|
+
### buildTools
|
46
|
+
|
47
|
+
Question: Please select the bundler.
|
48
|
+
|
49
|
+
Options:
|
50
|
+
|
51
|
+
- webpack -- webpack
|
52
|
+
|
53
|
+
- Rspack -- rspack
|
54
|
+
|
55
|
+
## Npm Module
|
56
|
+
|
57
|
+
### packageName
|
58
|
+
|
59
|
+
Question: Please fill in the project name.
|
60
|
+
|
61
|
+
:::info
|
62
|
+
The value of the `name` field in the `package.json` file of the Npm module, which is a string type.
|
63
|
+
:::
|
64
|
+
|
65
|
+
<LanguageConfig />
|
66
|
+
|
67
|
+
<PackageManager />
|
68
|
+
|
69
|
+
## Modern Doc
|
70
|
+
|
71
|
+
<PackageManager />
|
72
|
+
|
73
|
+
## Monorepo
|
74
|
+
|
75
|
+
<PackageManager />
|
@@ -0,0 +1,151 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 2
|
3
|
+
---
|
4
|
+
|
5
|
+
# CLI Options
|
6
|
+
|
7
|
+
`@modern-js/create` provides many configuration parameters to configure its behavior during execution, which can be viewed using the `--help` parameter:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
npx @modern-js/create@latest --help
|
11
|
+
|
12
|
+
Usage: npx @modern-js/create@latest [projectDir]
|
13
|
+
|
14
|
+
create Modern.js solution project
|
15
|
+
|
16
|
+
Options:
|
17
|
+
--version show create tools version
|
18
|
+
--lang <lang> set create tools language(en or zh)
|
19
|
+
-c, --config <config> set default project config(json string) (default: "{}")
|
20
|
+
-d,--debug using debug mode to log something (default: false)
|
21
|
+
--mwa create mwa application using default config (default: false)
|
22
|
+
--module create module application using default config (default: false)
|
23
|
+
--monorepo create monorepo application using default config (default: false)
|
24
|
+
--generator <generator> run custom generator
|
25
|
+
-p, --plugin <plugin> use generator plugin to create new solution or customize Modern.js solution (default: [])
|
26
|
+
--dist-tag <distTag> use specified tag version for it\'s generator (default: "")
|
27
|
+
--packages <packages> set project specific dependency version information (default: "{}")
|
28
|
+
--registry <registry> set npm registry url to run npm command (default: "")
|
29
|
+
--no-need-install not run install command
|
30
|
+
-h, --help display help for command
|
31
|
+
|
32
|
+
Commands:
|
33
|
+
clean-cache clean locale generator cache
|
34
|
+
```
|
35
|
+
|
36
|
+
The following will provide a detailed introduction to these parameters:
|
37
|
+
|
38
|
+
## [projectDir]
|
39
|
+
|
40
|
+
The project directory name.
|
41
|
+
|
42
|
+
When executing `@modern-js/create`, a `projectDir` folder will be created in the current directory by default, and the project will be initialized in this folder. If this parameter is empty, the initialization project will be directly generated in the current directory.
|
43
|
+
|
44
|
+
:::info
|
45
|
+
If the contents of the directory where `projectDir` is located are not empty, a prompt will be given whether to continue creating. It is recommended to perform project initialization operations in an empty directory.
|
46
|
+
:::
|
47
|
+
|
48
|
+
## --version
|
49
|
+
|
50
|
+
Get the version of the `@modern-js/create` tool.
|
51
|
+
|
52
|
+
```bash
|
53
|
+
npx @modern-js/create@latest --version
|
54
|
+
|
55
|
+
[INFO] @modern-js/create v2.21.1
|
56
|
+
```
|
57
|
+
|
58
|
+
## --lang \<lang>
|
59
|
+
|
60
|
+
The execution language, supports `zh` and `en`.
|
61
|
+
|
62
|
+
By default, `@modern-js/create` will automatically identify the user's system language and choose to use Chinese or English. If the identification fails or does not meet usage habits, you can manually specify it using this parameter.
|
63
|
+
|
64
|
+
## -c, --config \<config>
|
65
|
+
|
66
|
+
Specify the default project configuration.
|
67
|
+
|
68
|
+
By default, `@modern-js/create` will prompt for interactive questions such as language selection and package management tools during the execution process. When it is necessary to specify these configuration contents in advance, they can be passed in through this field.
|
69
|
+
|
70
|
+
This field is a JSON string. For example, when specifying a package management tool:
|
71
|
+
|
72
|
+
```bash
|
73
|
+
npx @modern-js/create@latest --config '{"packageManager": "pnpm"}'
|
74
|
+
```
|
75
|
+
|
76
|
+
Supported parameters for `config` can be found at [Configuration Parameters](/guides/topic-detail/generator/create/config.html)。
|
77
|
+
|
78
|
+
## -d,--debug
|
79
|
+
|
80
|
+
Display debug logs.
|
81
|
+
|
82
|
+
When encountering problems during use, you can use this parameter to display debug logs, which is convenient for quickly locating the problem position and troubleshooting.
|
83
|
+
|
84
|
+
## --mwa
|
85
|
+
|
86
|
+
Quickly create a Web App project.
|
87
|
+
|
88
|
+
## --module
|
89
|
+
|
90
|
+
Quickly create a Npm Module project.
|
91
|
+
|
92
|
+
## --monorepo
|
93
|
+
|
94
|
+
Quickly create a Monorepo project.
|
95
|
+
|
96
|
+
## -p, --plugin \<plugin>
|
97
|
+
|
98
|
+
Specify a generator plugin.
|
99
|
+
|
100
|
+
`@modern-js/create` supports customizing the default project solution type of Modern.js or adding project solution type scenarios using generator plugin. For details, please refer to [Developing Generator Plugin](/guides/topic-detail/generator/plugin/structure.html).
|
101
|
+
|
102
|
+
## --generator \<generator>
|
103
|
+
|
104
|
+
Specify a micro-generator.
|
105
|
+
|
106
|
+
<!-- TODO 详情可查看[开发微生成器]-->
|
107
|
+
`@modern-js/create` supports completely customizing the project generation process using micro-generator.
|
108
|
+
|
109
|
+
## --dist-tag \<distTag>
|
110
|
+
|
111
|
+
Specify the version of the generator and Modern.js-related dependencies.
|
112
|
+
|
113
|
+
During the execution of `@modern-js/create`, a smaller micro-generator will be executed by default, and the `latest` version of the micro-generator will be used by default. This parameter can be used to specify the version number of the micro-generator to be executed and the version of the installed Modern.js-related dependencies.
|
114
|
+
|
115
|
+
For example, use the `next` version:
|
116
|
+
|
117
|
+
```bash
|
118
|
+
npx @modern-js/create@next --dist-tag next
|
119
|
+
```
|
120
|
+
|
121
|
+
## --packages \<packages>
|
122
|
+
|
123
|
+
Specify specific package version dependencies when creating a project.
|
124
|
+
|
125
|
+
If you need to specify a specific package version when creating a project, you can use this parameter. This parameter will configure `pnpm.overrides` (if the package management tool is pnpm) or `resolutions` to lock the package version number in the `package.json` file in the project root directory.
|
126
|
+
|
127
|
+
The parameter value is a JSON string.
|
128
|
+
|
129
|
+
For example, specify the react version:
|
130
|
+
|
131
|
+
```bash
|
132
|
+
npx @modern-js/create@latest --packages '{"react":"^17"}'
|
133
|
+
```
|
134
|
+
|
135
|
+
## --registry \<registry>
|
136
|
+
|
137
|
+
Specify the sub-generator to execute and the npm registry to fetch project dependencies version.
|
138
|
+
|
139
|
+
## --no-need-install
|
140
|
+
|
141
|
+
Ignore automatic installation of dependencies.
|
142
|
+
|
143
|
+
By default, `@modern-js/create` will automatically install dependencies after creating a project. Using this parameter can ignore the installation of dependencies.
|
144
|
+
|
145
|
+
## clean-cache
|
146
|
+
|
147
|
+
The `@modern-js/create` command generates sub-generators cache in the tmp directory of the execution machine by default to speed up the generator execution. This command can be used to delete the cache when it needs to be refreshed or when there are problems with the cache.
|
148
|
+
|
149
|
+
```bash
|
150
|
+
npx @modern-js/create@latest clean-cache
|
151
|
+
```
|
@@ -0,0 +1,66 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 1
|
3
|
+
---
|
4
|
+
|
5
|
+
# Usage
|
6
|
+
|
7
|
+
Modern.js provides `@modern-js/create` tool for creating project templates provided by Modern.js, including [Web App](https://modernjs.dev/), [Npm Module](https://modernjs.dev/module-tools), [Modern Doc](https://modernjs.dev/doc-tools), [Monorepo](/guides/topic-detail/monorepo/intro.html).
|
8
|
+
|
9
|
+
The following will introduce how to use `@modern-js/create`.
|
10
|
+
|
11
|
+
## Environment Preparation
|
12
|
+
|
13
|
+
import Prerequisites from "@site-docs-en/components/prerequisites"
|
14
|
+
|
15
|
+
<Prerequisites />
|
16
|
+
|
17
|
+
## Create a Project with `@modern-js/create`
|
18
|
+
|
19
|
+
You do not need to install `@modern-js/create` globally, just use npx to run it:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
npx @modern-js/create@latest [projectDir]
|
23
|
+
```
|
24
|
+
|
25
|
+
:::info
|
26
|
+
`[projectDir]` is the project directory name. If it is not filled in, the project will be created in the current directory.
|
27
|
+
:::
|
28
|
+
|
29
|
+
During the execution, complete the interaction according to the prompt to create a project that meets your requirements.
|
30
|
+
|
31
|
+
### Create an Web APP Project
|
32
|
+
|
33
|
+
```bash
|
34
|
+
npx @modern-js/create@latest web-app
|
35
|
+
? Please select the type of project you want to create: Web App
|
36
|
+
? Please select the programming language: TS
|
37
|
+
? Please select the package manager: pnpm
|
38
|
+
? Please select the bundler: webpack
|
39
|
+
```
|
40
|
+
|
41
|
+
### Create an Npm Module Project
|
42
|
+
|
43
|
+
```bash
|
44
|
+
npx @modern-js/create@latest npm-module
|
45
|
+
? Please select the type of project you want to create: Npm Module
|
46
|
+
? Please fill in the project name: npm-module
|
47
|
+
? Please select the programming language: TS
|
48
|
+
? Please select the package manager: pnpm
|
49
|
+
```
|
50
|
+
|
51
|
+
### Create a Modern Doc Project
|
52
|
+
|
53
|
+
```bash
|
54
|
+
npx @modern-js/create@latest doc-website
|
55
|
+
? Please select the type of project you want to create: Doc Site
|
56
|
+
? Please select the package manager: pnpm
|
57
|
+
```
|
58
|
+
|
59
|
+
### Create Monorepo Project
|
60
|
+
|
61
|
+
```bash
|
62
|
+
npx @modern-js/create@latest monorepo
|
63
|
+
? Please select the type of project you want to create: Doc Site
|
64
|
+
? Please select the package manager: pnpm
|
65
|
+
```
|
66
|
+
|