@modern-js/main-doc 2.58.3 → 2.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/en/_meta.json +10 -5
- package/docs/en/apis/app/hooks/api/lambda.mdx +4 -48
- package/docs/en/apis/app/hooks/api/middleware.mdx +11 -0
- package/docs/en/apis/app/runtime/core/use-loader.mdx +1 -1
- package/docs/en/community/blog/v2-release-note.mdx +1 -1
- package/docs/en/components/enable-bff.mdx +19 -2
- package/docs/en/components/extend-bff-function.mdx +5 -0
- package/docs/en/components/init-app.mdx +0 -1
- package/docs/en/components/init-rspack-app.mdx +0 -1
- package/docs/en/components/other-plugins.mdx +0 -0
- package/docs/en/components/ssr-monitor.mdx +3 -0
- package/docs/en/configure/app/auto-load-plugin.mdx +4 -0
- package/docs/en/configure/app/output/ssg.mdx +52 -141
- package/docs/en/configure/app/plugins.mdx +2 -2
- package/docs/en/configure/app/tools/esbuild.mdx +1 -1
- package/docs/en/configure/app/tools/swc.mdx +1 -1
- package/docs/en/configure/app/tools/tailwindcss.mdx +1 -1
- package/docs/en/guides/_meta.json +0 -5
- package/docs/en/guides/advanced-features/_meta.json +3 -8
- package/docs/en/guides/advanced-features/bff/_meta.json +1 -1
- package/docs/en/guides/advanced-features/bff/extend-server.mdx +154 -0
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +52 -123
- package/docs/en/guides/advanced-features/bff/function.mdx +108 -80
- package/docs/en/guides/advanced-features/bff/sdk.mdx +40 -51
- package/docs/en/guides/advanced-features/build-performance.mdx +6 -21
- package/docs/en/guides/advanced-features/page-performance/_meta.json +1 -0
- package/docs/en/guides/advanced-features/rspack-start.mdx +6 -14
- package/docs/en/guides/basic-features/_meta.json +31 -9
- package/docs/en/guides/basic-features/css/_meta.json +1 -0
- package/docs/en/guides/basic-features/css/css-in-js.mdx +34 -0
- package/docs/en/guides/basic-features/{css-modules.mdx → css/css-modules.mdx} +0 -4
- package/docs/en/guides/basic-features/css/css.mdx +25 -0
- package/docs/en/guides/basic-features/{css.mdx → css/tailwindcss.mdx} +5 -66
- package/docs/en/guides/basic-features/data/data-fetch.mdx +134 -235
- package/docs/en/guides/basic-features/data/data-write.mdx +66 -77
- package/docs/en/guides/basic-features/debug/_meta.json +1 -0
- package/docs/en/guides/basic-features/debug/rsdoctor.mdx +57 -0
- package/docs/en/guides/{advanced-features → basic-features/debug}/using-storybook.mdx +2 -0
- package/docs/en/guides/basic-features/render/_meta.json +1 -0
- package/docs/en/guides/basic-features/render/ssg.mdx +208 -0
- package/docs/en/guides/{advanced-features/ssr/cache.mdx → basic-features/render/ssr-cache.mdx} +38 -50
- package/docs/en/guides/basic-features/render/ssr.mdx +301 -0
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +230 -0
- package/docs/en/guides/basic-features/routes.mdx +274 -263
- package/docs/en/guides/basic-features/static-assets/_meta.json +1 -0
- package/docs/en/guides/basic-features/static-assets.mdx +2 -2
- package/docs/en/guides/basic-features/testing/_meta.json +1 -0
- package/docs/en/guides/basic-features/testing/cypress.mdx +95 -0
- package/docs/en/guides/basic-features/testing/jest.mdx +148 -0
- package/docs/en/guides/basic-features/testing/playwright.mdx +111 -0
- package/docs/en/guides/basic-features/testing/vitest.mdx +100 -0
- package/docs/en/guides/concept/entries.mdx +9 -2
- package/docs/en/guides/deprecated.md +2 -0
- package/docs/en/guides/get-started/quick-start.mdx +1 -1
- package/docs/en/guides/get-started/tech-stack.mdx +4 -4
- package/docs/en/guides/topic-detail/_meta.json +0 -6
- package/docs/en/guides/topic-detail/generator/create/config.mdx +0 -10
- package/docs/en/guides/topic-detail/generator/create/use.mdx +0 -1
- package/docs/en/plugin/_meta.json +19 -0
- package/docs/en/plugin/cli-plugins/_meta.json +1 -0
- package/docs/en/plugin/cli-plugins/plugin-bff.mdx +5 -0
- package/docs/en/plugin/cli-plugins/plugin-ssg.mdx +5 -0
- package/docs/en/{guides/rsbuild-plugins → plugin/cli-plugins}/plugin-swc.mdx +7 -0
- package/docs/en/plugin/cli-plugins/plugin-tailwind.mdx +5 -0
- package/docs/en/plugin/cli-plugins.mdx +6 -0
- package/docs/en/{guides/advanced-features/rsbuild-plugin.mdx → plugin/introduction.mdx} +36 -11
- package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/extend.mdx +1 -1
- package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/implement.mdx +3 -3
- package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/plugin-api.mdx +2 -2
- package/docs/en/plugin/rsbuild-plugins/_meta.json +1 -0
- package/docs/en/plugin/rsbuild-plugins.mdx +3 -0
- package/docs/en/tutorials/first-app/c03-css.mdx +1 -1
- package/docs/zh/_meta.json +10 -5
- package/docs/zh/apis/app/hooks/api/lambda.mdx +5 -48
- package/docs/zh/apis/app/hooks/api/middleware.mdx +11 -0
- package/docs/zh/apis/app/runtime/core/use-loader.mdx +1 -1
- package/docs/zh/community/blog/v2-release-note.mdx +1 -1
- package/docs/zh/components/enable-bff.mdx +19 -2
- package/docs/zh/components/extend-bff-function.mdx +5 -0
- package/docs/zh/components/init-app.mdx +0 -1
- package/docs/zh/components/init-rspack-app.mdx +0 -1
- package/docs/zh/components/other-plugins.mdx +0 -0
- package/docs/zh/components/ssr-monitor.mdx +3 -0
- package/docs/zh/configure/app/auto-load-plugin.mdx +4 -0
- package/docs/zh/configure/app/output/ssg.mdx +49 -139
- package/docs/zh/configure/app/plugins.mdx +2 -2
- package/docs/zh/configure/app/tools/esbuild.mdx +1 -1
- package/docs/zh/configure/app/tools/swc.mdx +1 -1
- package/docs/zh/configure/app/tools/tailwindcss.mdx +1 -1
- package/docs/zh/guides/_meta.json +0 -5
- package/docs/zh/guides/advanced-features/_meta.json +3 -8
- package/docs/zh/guides/advanced-features/bff/_meta.json +1 -1
- package/docs/zh/guides/advanced-features/bff/extend-server.mdx +156 -0
- package/docs/zh/guides/advanced-features/bff/frameworks.mdx +51 -117
- package/docs/zh/guides/advanced-features/bff/function.mdx +69 -59
- package/docs/zh/guides/advanced-features/bff/sdk.mdx +27 -36
- package/docs/zh/guides/advanced-features/build-performance.mdx +6 -21
- package/docs/zh/guides/advanced-features/page-performance/_meta.json +1 -0
- package/docs/zh/guides/advanced-features/rspack-start.mdx +8 -17
- package/docs/zh/guides/basic-features/_meta.json +31 -9
- package/docs/zh/guides/basic-features/alias.mdx +5 -11
- package/docs/zh/guides/basic-features/css/_meta.json +1 -0
- package/docs/zh/guides/basic-features/css/css-in-js.mdx +34 -0
- package/docs/zh/guides/basic-features/css/css.mdx +25 -0
- package/docs/zh/guides/basic-features/{css.mdx → css/tailwindcss.mdx} +3 -64
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +96 -211
- package/docs/zh/guides/basic-features/data/data-write.mdx +54 -55
- package/docs/zh/guides/basic-features/debug/_meta.json +1 -0
- package/docs/zh/guides/basic-features/debug/rsdoctor.mdx +57 -0
- package/docs/zh/guides/{advanced-features → basic-features/debug}/using-storybook.mdx +1 -1
- package/docs/zh/guides/basic-features/env-vars.mdx +1 -1
- package/docs/zh/guides/basic-features/render/_meta.json +1 -0
- package/docs/zh/guides/basic-features/render/ssg.mdx +210 -0
- package/docs/zh/guides/{advanced-features/ssr/cache.mdx → basic-features/render/ssr-cache.mdx} +16 -26
- package/docs/zh/guides/basic-features/render/ssr.mdx +309 -0
- package/docs/zh/guides/{advanced-features/ssr/stream.mdx → basic-features/render/streaming-ssr.mdx} +22 -37
- package/docs/zh/guides/basic-features/routes.mdx +251 -237
- package/docs/zh/guides/basic-features/static-assets/_meta.json +1 -0
- package/docs/zh/guides/basic-features/static-assets.mdx +3 -7
- package/docs/zh/guides/basic-features/testing/_meta.json +1 -0
- package/docs/zh/guides/basic-features/testing/cypress.mdx +95 -0
- package/docs/zh/guides/basic-features/testing/jest.mdx +148 -0
- package/docs/zh/guides/basic-features/testing/playwright.mdx +112 -0
- package/docs/zh/guides/basic-features/testing/vitest.mdx +100 -0
- package/docs/zh/guides/concept/entries.mdx +6 -3
- package/docs/zh/guides/deprecated.md +4 -0
- package/docs/zh/guides/get-started/quick-start.mdx +1 -1
- package/docs/zh/guides/get-started/tech-stack.mdx +8 -8
- package/docs/zh/guides/topic-detail/_meta.json +0 -6
- package/docs/zh/guides/topic-detail/generator/create/config.mdx +0 -10
- package/docs/zh/guides/topic-detail/generator/create/use.mdx +0 -1
- package/docs/zh/plugin/_meta.json +19 -0
- package/docs/zh/plugin/cli-plugins/_meta.json +1 -0
- package/docs/zh/plugin/cli-plugins/plugin-bff.mdx +5 -0
- package/docs/zh/plugin/cli-plugins/plugin-ssg.mdx +5 -0
- package/docs/zh/{guides/rsbuild-plugins → plugin/cli-plugins}/plugin-swc.mdx +7 -0
- package/docs/zh/plugin/cli-plugins/plugin-tailwind.mdx +5 -0
- package/docs/zh/plugin/cli-plugins.mdx +6 -0
- package/docs/zh/{guides/advanced-features/rsbuild-plugin.mdx → plugin/introduction.mdx} +38 -13
- package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/extend.mdx +1 -1
- package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/implement.mdx +3 -3
- package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/plugin-api.mdx +2 -2
- package/docs/zh/plugin/rsbuild-plugins/_meta.json +1 -0
- package/docs/zh/plugin/rsbuild-plugins.mdx +4 -0
- package/docs/zh/tutorials/first-app/c03-css.mdx +1 -1
- package/i18n.json +42 -6
- package/package.json +7 -6
- package/rspress.config.ts +1 -58
- package/src/components/Footer/index.tsx +1 -1
- package/src/pages/index.tsx +0 -1
- package/docs/en/apis/app/hooks/api/api.mdx +0 -80
- package/docs/en/apis/app/hooks/api/app.mdx +0 -12
- package/docs/en/apis/app/hooks/config/storybook.mdx +0 -37
- package/docs/en/guides/advanced-features/bff/type.mdx +0 -46
- package/docs/en/guides/advanced-features/eslint.mdx +0 -148
- package/docs/en/guides/advanced-features/ssg.mdx +0 -116
- package/docs/en/guides/advanced-features/ssr/_meta.json +0 -1
- package/docs/en/guides/advanced-features/ssr/index.mdx +0 -23
- package/docs/en/guides/advanced-features/ssr/stream.mdx +0 -248
- package/docs/en/guides/advanced-features/ssr/usage.mdx +0 -341
- package/docs/en/guides/advanced-features/ssr.mdx +0 -555
- package/docs/zh/apis/app/hooks/api/api.mdx +0 -81
- package/docs/zh/apis/app/hooks/api/app.mdx +0 -12
- package/docs/zh/apis/app/hooks/config/storybook.mdx +0 -38
- package/docs/zh/guides/advanced-features/bff/type.mdx +0 -46
- package/docs/zh/guides/advanced-features/eslint.mdx +0 -152
- package/docs/zh/guides/advanced-features/ssg.mdx +0 -116
- package/docs/zh/guides/advanced-features/ssr/_meta.json +0 -1
- package/docs/zh/guides/advanced-features/ssr/index.mdx +0 -23
- package/docs/zh/guides/advanced-features/ssr/usage.mdx +0 -329
- /package/docs/en/guides/advanced-features/{bff/index.mdx → bff.mdx} +0 -0
- /package/docs/en/guides/advanced-features/{code-split.mdx → page-performance/code-split.mdx} +0 -0
- /package/docs/en/guides/advanced-features/{inline-assets.mdx → page-performance/inline-assets.mdx} +0 -0
- /package/docs/en/guides/advanced-features/{optimize-bundle.mdx → page-performance/optimize-bundle.mdx} +0 -0
- /package/docs/en/guides/basic-features/{mock.mdx → debug/mock.mdx} +0 -0
- /package/docs/en/guides/basic-features/{proxy.mdx → debug/proxy.mdx} +0 -0
- /package/docs/en/guides/basic-features/{json-files.mdx → static-assets/json-files.mdx} +0 -0
- /package/docs/en/guides/basic-features/{svg-assets.mdx → static-assets/svg-assets.mdx} +0 -0
- /package/docs/en/guides/basic-features/{wasm-assets.mdx → static-assets/wasm-assets.mdx} +0 -0
- /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/_meta.json +0 -0
- /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook-list.mdx +0 -0
- /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook.mdx +0 -0
- /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/introduction.mdx +0 -0
- /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/lifecycle.mdx +0 -0
- /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/relationship.mdx +0 -0
- /package/docs/en/{guides → plugin}/rsbuild-plugins/plugin-esbuild.mdx +0 -0
- /package/docs/zh/guides/advanced-features/{bff/index.mdx → bff.mdx} +0 -0
- /package/docs/zh/guides/advanced-features/{code-split.mdx → page-performance/code-split.mdx} +0 -0
- /package/docs/zh/guides/advanced-features/{inline-assets.mdx → page-performance/inline-assets.mdx} +0 -0
- /package/docs/zh/guides/advanced-features/{optimize-bundle.mdx → page-performance/optimize-bundle.mdx} +0 -0
- /package/docs/zh/guides/basic-features/{css-modules.mdx → css/css-modules.mdx} +0 -0
- /package/docs/zh/guides/basic-features/{mock.mdx → debug/mock.mdx} +0 -0
- /package/docs/zh/guides/basic-features/{proxy.mdx → debug/proxy.mdx} +0 -0
- /package/docs/zh/guides/basic-features/{json-files.mdx → static-assets/json-files.mdx} +0 -0
- /package/docs/zh/guides/basic-features/{svg-assets.mdx → static-assets/svg-assets.mdx} +0 -0
- /package/docs/zh/guides/basic-features/{wasm-assets.mdx → static-assets/wasm-assets.mdx} +0 -0
- /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/_meta.json +0 -0
- /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook-list.mdx +0 -0
- /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook.mdx +0 -0
- /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/introduction.mdx +0 -0
- /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/lifecycle.mdx +0 -0
- /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/relationship.mdx +0 -0
- /package/docs/zh/{guides → plugin}/rsbuild-plugins/plugin-esbuild.mdx +0 -0
|
@@ -1,11 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
sidebar_position: 21
|
|
3
|
-
title: Using Rsbuild Plugin
|
|
4
|
-
---
|
|
1
|
+
# Plugin
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
In Modern.js, you can directly use two types of plugins: Modern.js framework plugins and Rsbuild plugins.
|
|
7
4
|
|
|
8
|
-
##
|
|
5
|
+
## Modern.js Framework Plugin
|
|
6
|
+
|
|
7
|
+
Modern.js has its own framework plugin system. You can use Modern.js plugins by configuring the [`plugins`](/configure/app/plugins) field in `modern.config.ts`.
|
|
8
|
+
|
|
9
|
+
### Plugin Types
|
|
10
|
+
|
|
11
|
+
Framework plugins can be categorized into three types:
|
|
12
|
+
|
|
13
|
+
1. [CLI Plugins](/plugin/cli-plugins): These are used to provide additional functionality when the Modern.js commands are executed in the application. Examples include adding commands, modifying configuration, and monitoring files. Most build-related capabilities can be achieved through CLI plugins.
|
|
14
|
+
2. Server Plugins: These add extra functionality when the application receives requests. Examples include adding middleware and modifying request responses.
|
|
15
|
+
3. Runtime Plugins: These provide additional functionality when the application runs React code. Examples include performing initialization actions and wrapping React higher-order components.
|
|
16
|
+
|
|
17
|
+
:::note
|
|
18
|
+
Server plugins and Runtime plugins are coming soon.
|
|
19
|
+
:::
|
|
20
|
+
|
|
21
|
+
### Developing Plugins
|
|
22
|
+
|
|
23
|
+
If you need to develop Modern.js framework plugins, you can read [Modern.js Plugin System](/plugin/plugin-system/introduction) for more information.
|
|
9
24
|
|
|
10
25
|
Rsbuild is the build tool of Modern.js. You can modify the default build behavior and add various additional features by adding the Rsbuild plugin, including but not limited to:
|
|
11
26
|
|
|
@@ -22,9 +37,15 @@ Modern.js has upgraded the build tool to [Rsbuild](https://rsbuild.dev/) startin
|
|
|
22
37
|
If your current version is lower than MAJOR_VERSION.46.0, you can upgrade by executing `npx modern upgrade`.
|
|
23
38
|
:::
|
|
24
39
|
|
|
25
|
-
|
|
40
|
+
:::info
|
|
41
|
+
For more information about the Rsbuild plugin system, you can read [Rsbuild Official Site - Plugins](https://rsbuild.dev/plugins/list/index).
|
|
42
|
+
:::
|
|
43
|
+
|
|
44
|
+
## Rsbuild Plugin
|
|
26
45
|
|
|
27
|
-
###
|
|
46
|
+
### Official Plugins
|
|
47
|
+
|
|
48
|
+
#### Builtin Plugins
|
|
28
49
|
|
|
29
50
|
Here are the official Rsbuild plugins built into Modern.js:
|
|
30
51
|
|
|
@@ -41,13 +62,17 @@ Here are the official Rsbuild plugins built into Modern.js:
|
|
|
41
62
|
| [CSS Minimizer Plugin](https://github.com/rspack-contrib/rsbuild-plugin-css-minimizer) | Used to customize CSS minimizer, switch to [cssnano](https://cssnano.co/) or other tools for CSS compression | [tools.minifyCss](/configure/app/tools/minify-css.html) |
|
|
42
63
|
| [Pug Plugin](https://github.com/rspack-contrib/rsbuild-plugin-pug) | Provides support for the Pug template engine | [tools.pug](/configure/app/tools/pug.html) |
|
|
43
64
|
| [Rem Plugin](https://github.com/rspack-contrib/rsbuild-plugin-rem) | Implements the rem adaptive layout for mobile pages | [output.convertToRem](/configure/app/output/convert-to-rem.html) |
|
|
44
|
-
| [YAML Plugin](https://github.com/rspack-contrib/rsbuild-plugin-yaml) | Used to import YAML files and convert them into JavaScript objects | [TOML File](/guides/basic-features/json-files.html#toml-file) |
|
|
45
|
-
| [TOML Plugin](https://github.com/rspack-contrib/rsbuild-plugin-toml) | Used to import TOML files and convert them into JavaScript objects | [YAML File](/guides/basic-features/json-files.html#yaml-file) |
|
|
65
|
+
| [YAML Plugin](https://github.com/rspack-contrib/rsbuild-plugin-yaml) | Used to import YAML files and convert them into JavaScript objects | [TOML File](/guides/basic-features/static-assets/json-files.html#toml-file) |
|
|
66
|
+
| [TOML Plugin](https://github.com/rspack-contrib/rsbuild-plugin-toml) | Used to import TOML files and convert them into JavaScript objects | [YAML File](/guides/basic-features/static-assets/json-files.html#yaml-file) |
|
|
46
67
|
|
|
47
|
-
|
|
68
|
+
#### Un-builtin Plugins
|
|
48
69
|
|
|
49
70
|
Here are the official Rsbuild plugins that are not built into Modern.js:
|
|
50
71
|
|
|
51
72
|
- [Image Compress Plugin](https://github.com/rspack-contrib/rsbuild-plugin-image-compress): Compress the image resources used in the project.
|
|
52
73
|
- [Stylus Plugin](https://rsbuild.dev/plugins/list/plugin-stylus): Use Stylus as the CSS preprocessor.
|
|
53
74
|
- [UMD Plugin](https://github.com/rspack-contrib/rsbuild-plugin-umd): Used to build outputs in UMD format.
|
|
75
|
+
|
|
76
|
+
import OtherPlugins from '@site-docs-en/components/other-plugins.mdx';
|
|
77
|
+
|
|
78
|
+
<OtherPlugins />
|
|
@@ -4,7 +4,7 @@ sidebar_position: 5
|
|
|
4
4
|
|
|
5
5
|
# Extending Plugin Hooks
|
|
6
6
|
|
|
7
|
-
This section describes how to extend plugin Hooks by dynamically registering [Hook models](/
|
|
7
|
+
This section describes how to extend plugin Hooks by dynamically registering [Hook models](/plugin/plugin-system/hook).
|
|
8
8
|
|
|
9
9
|
## Example
|
|
10
10
|
|
|
@@ -28,7 +28,7 @@ const myPlugin = {
|
|
|
28
28
|
};
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
In addition, plugins allow configuration of the execution order with other plugins. For more information, please refer to [Plugin Relationship](/
|
|
31
|
+
In addition, plugins allow configuration of the execution order with other plugins. For more information, please refer to [Plugin Relationship](/plugin/plugin-system/relationship).
|
|
32
32
|
|
|
33
33
|
### Plugin Types
|
|
34
34
|
|
|
@@ -108,7 +108,7 @@ import type { MyPluginHook } from 'xxx';
|
|
|
108
108
|
const myPlugin: CliPlugin<AppTools & { hooks: MyPluginHook }> = {};
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
Please refer to [Extending Hooks](/
|
|
111
|
+
Please refer to [Extending Hooks](/plugin/plugin-system/extend) for detailed explanations.
|
|
112
112
|
|
|
113
113
|
### Plugin Configuration
|
|
114
114
|
|
|
@@ -151,7 +151,7 @@ export const myPlugin = (): CliPlugin => ({
|
|
|
151
151
|
});
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
-
For more detail [Plugin API](/
|
|
154
|
+
For more detail [Plugin API](/plugin/plugin-system/plugin-api).
|
|
155
155
|
|
|
156
156
|
### Async setup
|
|
157
157
|
|
package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/plugin-api.mdx
RENAMED
|
@@ -44,7 +44,7 @@ interface UserConfig {
|
|
|
44
44
|
Please refer to [Configuration](/configure/app/usage) for the specific meanings of configuration fields.
|
|
45
45
|
|
|
46
46
|
:::tip
|
|
47
|
-
This method returns a read-only configuration and cannot be modified. If you need to modify the configuration, please use [config hook](/
|
|
47
|
+
This method returns a read-only configuration and cannot be modified. If you need to modify the configuration, please use [config hook](/plugin/plugin-system/hook-list.html#config).
|
|
48
48
|
:::
|
|
49
49
|
|
|
50
50
|
### useResolvedConfigContext
|
|
@@ -67,7 +67,7 @@ interface NormalizedConfig {
|
|
|
67
67
|
Please refer to [Configuration](/configure/app/usage) for the specific meanings of configuration fields.
|
|
68
68
|
|
|
69
69
|
:::tip
|
|
70
|
-
This method returns a read-only configuration and cannot be modified. If you need to modify the configuration, please use [config hook](/
|
|
70
|
+
This method returns a read-only configuration and cannot be modified. If you need to modify the configuration, please use [config hook](/plugin/plugin-system/hook-list.html#config).
|
|
71
71
|
:::
|
|
72
72
|
|
|
73
73
|
### useAppContext
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
["plugin-esbuild"]
|
|
@@ -294,7 +294,7 @@ A Utility Class named `custom-text-gray` is implemented in `src/routes/styles/ut
|
|
|
294
294
|
```
|
|
295
295
|
|
|
296
296
|
:::info note
|
|
297
|
-
Modern.js integrates with [PostCSS](/guides/basic-features/css) and supports modern CSS syntax features such as [custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties).
|
|
297
|
+
Modern.js integrates with [PostCSS](/guides/basic-features/css/css) and supports modern CSS syntax features such as [custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties).
|
|
298
298
|
|
|
299
299
|
:::
|
|
300
300
|
|
package/docs/zh/_meta.json
CHANGED
|
@@ -4,21 +4,26 @@
|
|
|
4
4
|
"link": "/guides/get-started/introduction",
|
|
5
5
|
"activeMatch": "/guides/"
|
|
6
6
|
},
|
|
7
|
-
{
|
|
8
|
-
"text": "tutorials",
|
|
9
|
-
"link": "/tutorials/foundations/introduction",
|
|
10
|
-
"activeMatch": "/tutorials/"
|
|
11
|
-
},
|
|
12
7
|
{
|
|
13
8
|
"text": "configure",
|
|
14
9
|
"link": "/configure/app/usage",
|
|
15
10
|
"activeMatch": "/configure/"
|
|
16
11
|
},
|
|
12
|
+
{
|
|
13
|
+
"text": "plugin-menu",
|
|
14
|
+
"link": "/plugin/introduction",
|
|
15
|
+
"activeMatch": "/plugin/"
|
|
16
|
+
},
|
|
17
17
|
{
|
|
18
18
|
"text": "apis",
|
|
19
19
|
"link": "/apis/app/commands",
|
|
20
20
|
"activeMatch": "/apis/"
|
|
21
21
|
},
|
|
22
|
+
{
|
|
23
|
+
"text": "tutorials",
|
|
24
|
+
"link": "/tutorials/foundations/introduction",
|
|
25
|
+
"activeMatch": "/tutorials/"
|
|
26
|
+
},
|
|
22
27
|
{
|
|
23
28
|
"text": "community",
|
|
24
29
|
"link": "/community/showcase",
|
|
@@ -2,56 +2,13 @@
|
|
|
2
2
|
title: lambda/*.[tj]s
|
|
3
3
|
sidebar_position: 3
|
|
4
4
|
---
|
|
5
|
-
# lambda/*.[tj]s
|
|
6
|
-
|
|
7
|
-
在 [BFF 框架写法](/guides/advanced-features/bff/type.html#框架写法)下,声明 API 路由的文件。除了[某些约定文件](/apis/app/hooks/api/lambda#白名单)外,`lambda/` 目录下的文件会被注册为接口的路由。
|
|
8
|
-
|
|
9
|
-
:::info
|
|
10
|
-
使用 `api` 目录需要开启 BFF 功能,需要在项目下执行 new 命令启用「BFF」功能。
|
|
11
5
|
|
|
12
|
-
|
|
6
|
+
# lambda/*.[tj]s
|
|
13
7
|
|
|
14
|
-
|
|
15
|
-
该文件支持使用 `js` 或 `ts` 语言,但必须使用 `esm` 语法导出函数。
|
|
8
|
+
开启 BFF 后,`lambda/` 目录下的文件会按照约定被注册为 BFF 的路由。
|
|
16
9
|
|
|
10
|
+
:::note
|
|
11
|
+
文件支持使用 `js` 或 `ts` 语言,但必须使用 `esm` 语法导出函数。
|
|
17
12
|
:::
|
|
18
13
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
### 默认路由
|
|
22
|
-
|
|
23
|
-
路由系统会将以 `index` 命名的文件会被映射到上一层目录。
|
|
24
|
-
|
|
25
|
-
- `api/lambda/index.ts` -> `$BASENAME/`
|
|
26
|
-
- `api/lambda/user/index.ts` -> `$BASENAME/user`
|
|
27
|
-
|
|
28
|
-
### 多级路由
|
|
29
|
-
|
|
30
|
-
路由系统也支持解析多级的文件,如果创建文件夹结构,文件仍会以相同方式自动解析路由。
|
|
31
|
-
|
|
32
|
-
- `api/lambda/hello.ts` -> `$BASENAME/hello`
|
|
33
|
-
- `api/lambda/user/list.ts` -> `$BASENAME/user/list`
|
|
34
|
-
|
|
35
|
-
### 动态路由
|
|
36
|
-
|
|
37
|
-
路由系统支持通过 `[]` 命名的文件目录生成动态路由。
|
|
38
|
-
|
|
39
|
-
- `api/lambda/user/[username]/info.ts` -> `$BASENAME/user/:username/info`
|
|
40
|
-
- `api/lambda/user/[username]/delete.ts` -> `$BASENAME/user/:username/delete`
|
|
41
|
-
- `api/lambda/article/[id]/info.ts` -> `$BASENAME/article/:id/info`
|
|
42
|
-
|
|
43
|
-
其中的 `$BASENAME` 可以在 `modern.config.js` 中进行配置,默认值为 `/api`。
|
|
44
|
-
|
|
45
|
-
### 白名单
|
|
46
|
-
|
|
47
|
-
默认 `lambda` 目录下所有文件都会当作 BFF 函数文件去解析,但同样我们也设置了白名单,这些文件不被被解析:
|
|
48
|
-
|
|
49
|
-
- 命名以 `_` 开头的文件。例如:`_utils.ts`。
|
|
50
|
-
- 命名以 `_` 开头的文件夹下所有文件。例如:`_utils/index.ts`、`_utils/cp.ts`。
|
|
51
|
-
- 测试文件。例如:`foo.test.ts`。
|
|
52
|
-
- TypeScript 类型文件。例如:`hello.d.ts`。
|
|
53
|
-
- `node_module` 下的文件。
|
|
54
|
-
|
|
55
|
-
## 函数定义
|
|
56
|
-
|
|
57
|
-
和函数写法下[函数定义](/apis/app/hooks/api/api#函数定义)完全一致。
|
|
14
|
+
详细内容可以参考 [BFF 函数路由](/guides/advanced-features/bff/function.html#函数路由)。
|
|
@@ -52,7 +52,7 @@ function useLoader(loaderFn: LoaderFn, options: Options): ReturnData;
|
|
|
52
52
|
- `initialData`:首次执行前的初始数据,对应返回值中的 `data` 字段。
|
|
53
53
|
- `skip`:当值为 `true` 时,函数不执行。
|
|
54
54
|
- `params`:当 `params` 序列化结果发生改变时,函数会重新执行。同时,`params` 也会作为函数的第二个参数被传入。
|
|
55
|
-
- `static`:当值为 `true` 时,`useLoader` 用于 [SSG](/guides/
|
|
55
|
+
- `static`:当值为 `true` 时,`useLoader` 用于 [SSG](/guides/basic-features/render/ssg) 编译阶段数据的获取。
|
|
56
56
|
|
|
57
57
|
### 返回值
|
|
58
58
|
|
|
@@ -132,7 +132,7 @@ Modern.js 可以划分为三个核心部分:**CLI 工具、服务端和运行
|
|
|
132
132
|
|
|
133
133
|
在字节跳动内部,我们借助这些插件 API,结合公司内的基建和平台,封装出内部的企业级框架。如果你需要对 Modern.js 框架进行深度定制,也可以借助这些插件 API 来完成。
|
|
134
134
|
|
|
135
|
-
> 如果你对 Modern.js 的插件系统感兴趣,请阅读 [「Modern.js - 自定义插件」](https://modernjs.dev/
|
|
135
|
+
> 如果你对 Modern.js 的插件系统感兴趣,请阅读 [「Modern.js - 自定义插件」](https://modernjs.dev/plugin/plugin-system/introduction.html)文档。
|
|
136
136
|
|
|
137
137
|
### 嵌套路由
|
|
138
138
|
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { PackageManagerTabs } from '@theme';
|
|
2
|
+
|
|
3
|
+
1. 执行 `new` 命令:
|
|
4
|
+
|
|
5
|
+
<PackageManagerTabs command="run new" />
|
|
6
|
+
|
|
7
|
+
2. 按照提示,选择**启用 BFF 功能**:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
? 请选择你想要的操作 启用可选功能
|
|
11
|
+
? 请选择功能名称 启用「BFF」功能
|
|
12
|
+
? 请选择 BFF 类型 框架模式
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
:::note
|
|
16
|
+
目前推荐使用框架模式创建 BFF,后续我们将会移除 BFF 类型的概念。
|
|
17
|
+
:::
|
|
18
|
+
|
|
19
|
+
3. 根据选择的运行时框架,将下面的代码添加到 `modern.config.[tj]s` 中:
|
|
3
20
|
|
|
4
21
|
import { Tabs, Tab as TabItem } from "@theme";
|
|
5
22
|
|
|
File without changes
|
|
@@ -4,44 +4,22 @@ title: ssg
|
|
|
4
4
|
|
|
5
5
|
# output.ssg
|
|
6
6
|
|
|
7
|
-
- **类型:** `boolean` | `object`
|
|
7
|
+
- **类型:** `boolean` | `object`
|
|
8
8
|
- **默认值:** `undefined`
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
开启应用 SSG 功能的配置
|
|
11
11
|
|
|
12
|
-
:::
|
|
13
|
-
此配置需要在开启 SSG 功能情况下才会生效。请阅读 [静态站点生成](/guides/
|
|
12
|
+
:::tip 开启 SSG 功能
|
|
13
|
+
此配置需要在开启 SSG 功能情况下才会生效。请阅读 [静态站点生成](/guides/basic-features/render/ssg) 文档了解如何开启 SSG 功能及使用场景。
|
|
14
14
|
:::
|
|
15
15
|
|
|
16
|
-
:::info
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
:::info 前置阅读
|
|
17
|
+
SSG 功能使用与路由关联性较大,建议使用前先了解[路由方案](/guides/basic-features/routes)。
|
|
19
18
|
:::
|
|
20
19
|
|
|
21
|
-
##
|
|
22
|
-
|
|
23
|
-
### 单入口
|
|
24
|
-
|
|
25
|
-
当该配置设置为 `true` 时,将会默认开启所有入口的 SSG 功能。
|
|
26
|
-
|
|
27
|
-
对**自控式路由**而言,将会渲染入口的根路由。对**约定式路由**而言,将会渲染入口中每一条路由。
|
|
28
|
-
|
|
29
|
-
例如 `src/` 目录下有以下满足**约定式路由**的文件结构:
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
.
|
|
33
|
-
├── src
|
|
34
|
-
│ └── routes
|
|
35
|
-
│ ├── layout.tsx
|
|
36
|
-
│ ├── page.tsx
|
|
37
|
-
│ └── user
|
|
38
|
-
│ ├── layout.tsx
|
|
39
|
-
│ ├── page.tsx
|
|
40
|
-
│ └── profile
|
|
41
|
-
│ └── page.tsx
|
|
42
|
-
```
|
|
20
|
+
## Boolean 类型
|
|
43
21
|
|
|
44
|
-
|
|
22
|
+
当该配置设置为 `true` 时,将会默认开启所有入口的 SSG 功能。对**自控式路由**而言,将会渲染入口的根路由。对**约定式路由**而言,将会渲染入口中每一条路由。
|
|
45
23
|
|
|
46
24
|
```js
|
|
47
25
|
export default defineConfig({
|
|
@@ -51,39 +29,20 @@ export default defineConfig({
|
|
|
51
29
|
});
|
|
52
30
|
```
|
|
53
31
|
|
|
54
|
-
执行 `pnpm build` 构建应用后。`dist/` 目录将会生成三张 HTML 分别对应三条路由(不开启 SSG 时只有一张 HTML),并且所有 HTML 都已经渲染。
|
|
55
|
-
|
|
56
|
-
而例如下面的**自控式路由**:
|
|
57
|
-
|
|
58
|
-
import SelfRouteExample from "@site-docs/components/self-route-example";
|
|
59
|
-
|
|
60
|
-
<SelfRouteExample />
|
|
61
|
-
|
|
62
|
-
同样使用上面的配置,在执行 `pnpm run build` 后,只有入口路由 `/` 会生成渲染后的 HTML。
|
|
63
|
-
|
|
64
|
-
### 多入口
|
|
65
|
-
|
|
66
32
|
`output.ssg` 也可以按照入口配置,配置生效的规则同样由入口路由方式决定。
|
|
67
33
|
|
|
68
|
-
|
|
34
|
+
例如以下目录结构,分别存在约定式路由入口 `entryA` 和自控式路由入口 `entryB`:
|
|
69
35
|
|
|
70
36
|
```bash
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
│
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
│ │ └── user
|
|
78
|
-
│ │ ├── layout.tsx
|
|
79
|
-
│ │ ├── page.tsx
|
|
80
|
-
│ │ └── profile
|
|
81
|
-
│ │ └── page.tsx
|
|
82
|
-
│ └── entryB
|
|
83
|
-
│ └── App.tsx
|
|
37
|
+
.
|
|
38
|
+
└── src
|
|
39
|
+
├── entryA
|
|
40
|
+
│ └── routes
|
|
41
|
+
└── entryB
|
|
42
|
+
└── App.tsx
|
|
84
43
|
```
|
|
85
44
|
|
|
86
|
-
|
|
45
|
+
你可以指定 `entryA` 和 `entryB` 的不同 SSG 配置:
|
|
87
46
|
|
|
88
47
|
```js
|
|
89
48
|
export default defineConfig({
|
|
@@ -96,107 +55,58 @@ export default defineConfig({
|
|
|
96
55
|
});
|
|
97
56
|
```
|
|
98
57
|
|
|
99
|
-
### 配置路由
|
|
100
|
-
|
|
101
|
-
上述内容中提到,**自控式路由**默认只会开启入口路由的 SSG 配置。
|
|
102
|
-
|
|
103
|
-
可以在 `output.ssg` 中设置具体的路由,告知 Modern.js 开启这些客户端路由的 SSG 功能。例如上述 `src/App.tsx` 的文件内容为:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
<SelfRouteExample />
|
|
107
|
-
|
|
108
|
-
在 `modern.config.js` 中这样设置后,`/about` 路由也会开启 SSG 功能:
|
|
109
|
-
|
|
110
|
-
```js
|
|
111
|
-
export default defineConfig({
|
|
112
|
-
output: {
|
|
113
|
-
ssg: {
|
|
114
|
-
routes: ['/', '/about'],
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
Modern.js 将会自动根据入口拼接完整的 URL 并交给 SSG 插件完成渲染。
|
|
121
|
-
|
|
122
|
-
也可以为具体入口或路由配置请求头,例如:
|
|
123
|
-
|
|
124
|
-
```js
|
|
125
|
-
export default defineConfig({
|
|
126
|
-
output: {
|
|
127
|
-
ssg: {
|
|
128
|
-
headers: {},
|
|
129
|
-
routes: [
|
|
130
|
-
'/',
|
|
131
|
-
{
|
|
132
|
-
url: '/about',
|
|
133
|
-
headers: {},
|
|
134
|
-
},
|
|
135
|
-
],
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
```
|
|
140
|
-
|
|
141
58
|
:::info
|
|
142
|
-
|
|
143
|
-
|
|
59
|
+
更多关于**约定式路由**和**自控式路由**在开启 SSG 后的默认行为,请阅读 [静态站点生成](/guides/basic-features/render/ssg) 。
|
|
144
60
|
:::
|
|
145
61
|
|
|
146
|
-
|
|
62
|
+
## Object 类型
|
|
147
63
|
|
|
148
|
-
|
|
64
|
+
当值类型为 `Object` 时,可以配置如下属性。
|
|
149
65
|
|
|
150
|
-
|
|
66
|
+
### 配置类型
|
|
151
67
|
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
│ └── user
|
|
159
|
-
│ ├── layout.tsx
|
|
160
|
-
│ ├── page.tsx
|
|
161
|
-
│ └── profile
|
|
162
|
-
│ └── page.tsx
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
可以这样设置,禁用某一条客户端路由的默认行为:
|
|
68
|
+
```ts
|
|
69
|
+
type SSGRouteOptions = string | {
|
|
70
|
+
url: string;
|
|
71
|
+
params?: Record<string, any>[];
|
|
72
|
+
headers?: Record<string, any>;
|
|
73
|
+
};
|
|
166
74
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
});
|
|
75
|
+
type SSGOptions = {
|
|
76
|
+
preventDefault?: string[];
|
|
77
|
+
headers?: Record<string, any>;
|
|
78
|
+
routes?: SSGRouteOptions[];
|
|
79
|
+
};
|
|
175
80
|
```
|
|
176
81
|
|
|
177
|
-
###
|
|
82
|
+
### 示例
|
|
178
83
|
|
|
179
|
-
|
|
84
|
+
下面的示例配置中,SSG 会渲染 `/`、`/about` 和 `/user/:id` 三条路由对应的页面。
|
|
180
85
|
|
|
181
|
-
|
|
86
|
+
对于 `/user/:id` 路由,`cookies` 添加到请求头中,同时会将 `params` 中的 `id` 替换为 `modernjs`。
|
|
182
87
|
|
|
183
|
-
```
|
|
88
|
+
```ts title="modern.config.ts"
|
|
184
89
|
export default defineConfig({
|
|
185
90
|
output: {
|
|
186
91
|
ssg: {
|
|
187
92
|
routes: [
|
|
93
|
+
'/',
|
|
94
|
+
'/about',
|
|
188
95
|
{
|
|
189
96
|
url: '/user/:id',
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
97
|
+
headers: {
|
|
98
|
+
cookies: "name=modernjs"
|
|
99
|
+
},
|
|
100
|
+
params: [{
|
|
101
|
+
id: 'modernjs',
|
|
102
|
+
}],
|
|
103
|
+
}
|
|
196
104
|
],
|
|
197
|
-
}
|
|
198
|
-
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
199
107
|
});
|
|
200
108
|
```
|
|
201
109
|
|
|
202
|
-
|
|
110
|
+
:::note
|
|
111
|
+
多入口的情况和单入口的配置方式一致,这里不再额外介绍。
|
|
112
|
+
:::
|
|
@@ -9,7 +9,7 @@ sidebar_position: 9
|
|
|
9
9
|
|
|
10
10
|
用于配置自定义的 Modern.js 框架插件。
|
|
11
11
|
|
|
12
|
-
自定义插件的编写方式请参考 [如何编写插件](/
|
|
12
|
+
自定义插件的编写方式请参考 [如何编写插件](/plugin/plugin-system/implement)。
|
|
13
13
|
|
|
14
14
|
## 注意事项
|
|
15
15
|
|
|
@@ -33,7 +33,7 @@ Modern.js 中内置了三种不同的框架插件:
|
|
|
33
33
|
|
|
34
34
|
默认情况下,自定义插件会按照 `plugins` 数组的顺序依次执行,Modern.js 内置插件的执行时机早于自定义插件。
|
|
35
35
|
|
|
36
|
-
当插件内部使用了控制顺序的相关字段,比如 `pre`、`post` 时,会基于声明的字段对执行顺序进行调整,详见 [插件之间的关系](/
|
|
36
|
+
当插件内部使用了控制顺序的相关字段,比如 `pre`、`post` 时,会基于声明的字段对执行顺序进行调整,详见 [插件之间的关系](/plugin/plugin-system/relationship)。
|
|
37
37
|
|
|
38
38
|
## 示例
|
|
39
39
|
|
|
@@ -23,7 +23,7 @@ const tailwind = {
|
|
|
23
23
|
|
|
24
24
|
在使用 `tools.tailwindcss` 之前,你需要启用 Modern.js 的 Tailwind CSS 插件。
|
|
25
25
|
|
|
26
|
-
请阅读[「使用 Tailwind CSS」](/guides/basic-features/css
|
|
26
|
+
请阅读[「使用 Tailwind CSS」](/guides/basic-features/css/tailwindcss) 章节来了解开启方式。
|
|
27
27
|
|
|
28
28
|
### Function 类型
|
|
29
29
|
|