@modern-js/main-doc 3.9.3 → 3.10.1
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/apis/app/hooks/api/lambda.mdx +2 -1
- package/docs/en/apis/app/hooks/config/html.mdx +1 -0
- package/docs/en/apis/app/hooks/config/mock.mdx +1 -0
- package/docs/en/apis/app/hooks/config/public.mdx +1 -0
- package/docs/en/apis/app/hooks/config/upload.mdx +2 -3
- package/docs/en/apis/app/hooks/modern-config.mdx +1 -0
- package/docs/en/apis/app/hooks/shared.mdx +1 -0
- package/docs/en/apis/app/hooks/src/modern.runtime.mdx +1 -0
- package/docs/en/apis/app/hooks/src/routes.mdx +1 -0
- package/docs/en/apis/app/hooks/src/server.mdx +2 -1
- package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +1 -0
- package/docs/en/apis/app/runtime/core/create-root.mdx +4 -1
- package/docs/en/apis/app/runtime/core/render.mdx +6 -2
- package/docs/en/apis/app/runtime/core/runtime-context.mdx +17 -17
- package/docs/en/apis/app/runtime/router/router.mdx +9 -6
- package/docs/en/apis/app/runtime/ssr/no-ssr.mdx +1 -0
- package/docs/en/apis/app/runtime/utility/head.mdx +1 -0
- package/docs/en/apis/app/runtime/utility/loadable.mdx +1 -0
- package/docs/en/community/blog/v3-release-note.mdx +36 -27
- package/docs/en/community/contributing-guide.mdx +15 -33
- package/docs/en/components/default-browserslist.mdx +0 -1
- package/docs/en/components/deploy-command.mdx +1 -1
- package/docs/en/components/deploy.mdx +1 -1
- package/docs/en/components/entry-scan-logic.mdx +1 -1
- package/docs/en/components/init-app.mdx +9 -3
- package/docs/en/components/international/custom-instance-code.mdx +0 -1
- package/docs/en/components/micro-runtime-config.mdx +12 -9
- package/docs/en/components/nodeVersion.mdx +2 -2
- package/docs/en/components/rsc-deploy-tip.mdx +0 -1
- package/docs/en/components/ssr-monitor.mdx +1 -1
- package/docs/en/configure/app/bff/cross-project.mdx +2 -2
- package/docs/en/configure/app/bff/prefix.mdx +1 -1
- package/docs/en/configure/app/dev/lazy-compilation.mdx +17 -1
- package/docs/en/configure/app/dev/start-url.mdx +0 -1
- package/docs/en/configure/app/output/css-modules.mdx +1 -5
- package/docs/en/configure/app/output/dist-path.mdx +0 -1
- package/docs/en/configure/app/output/inline-scripts.mdx +1 -2
- package/docs/en/configure/app/output/inline-styles.mdx +1 -2
- package/docs/en/configure/app/output/split-route-chunks.mdx +1 -1
- package/docs/en/configure/app/output/ssg.mdx +1 -1
- package/docs/en/configure/app/output/ssgByEntries.mdx +1 -0
- package/docs/en/configure/app/performance/chunk-split.mdx +1 -4
- package/docs/en/configure/app/runtime/plugins.mdx +6 -4
- package/docs/en/configure/app/server/rsc.mdx +1 -1
- package/docs/en/configure/app/server/ssr.mdx +7 -8
- package/docs/en/configure/app/server/tsconfig-path.mdx +2 -2
- package/docs/en/configure/app/tools/less.mdx +5 -6
- package/docs/en/configure/app/tools/sass.mdx +5 -6
- package/docs/en/configure/app/tools/svgr.mdx +7 -7
- package/docs/en/configure/app/usage.mdx +1 -5
- package/docs/en/guides/advanced-features/bff/cross-project.mdx +5 -4
- package/docs/en/guides/advanced-features/compatibility.mdx +0 -1
- package/docs/en/guides/advanced-features/international/advanced.mdx +1 -1
- package/docs/en/guides/advanced-features/international/api.mdx +34 -28
- package/docs/en/guides/advanced-features/international/best-practices.mdx +15 -15
- package/docs/en/guides/advanced-features/international/configuration.mdx +37 -37
- package/docs/en/guides/advanced-features/international/locale-detection.mdx +37 -28
- package/docs/en/guides/advanced-features/international/resource-loading.mdx +19 -17
- package/docs/en/guides/advanced-features/international/routing.mdx +8 -6
- package/docs/en/guides/advanced-features/international.mdx +8 -8
- package/docs/en/guides/advanced-features/server-monitor/logger.mdx +5 -5
- package/docs/en/guides/advanced-features/server-monitor/metrics.mdx +8 -8
- package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +1 -3
- package/docs/en/guides/advanced-features/source-build.mdx +1 -1
- package/docs/en/guides/advanced-features/web-server.mdx +3 -3
- package/docs/en/guides/basic-features/data/data-fetch.mdx +1 -3
- package/docs/en/guides/basic-features/data/data-write.mdx +24 -28
- package/docs/en/guides/basic-features/debug/mock.mdx +2 -2
- package/docs/en/guides/basic-features/debug/using-storybook.mdx +5 -6
- package/docs/en/guides/basic-features/html.mdx +2 -3
- package/docs/en/guides/basic-features/output-files.mdx +1 -1
- package/docs/en/guides/basic-features/render/overview.mdx +12 -12
- package/docs/en/guides/basic-features/render/rsc.mdx +16 -9
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +5 -5
- package/docs/en/guides/basic-features/render/ssr.mdx +8 -12
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +2 -1
- package/docs/en/guides/basic-features/routes/config-routes.mdx +60 -59
- package/docs/en/guides/basic-features/testing/playwright.mdx +14 -8
- package/docs/en/guides/basic-features/testing/rstest.mdx +6 -4
- package/docs/en/guides/get-started/ai-coding-agents.mdx +6 -6
- package/docs/en/guides/get-started/introduction.mdx +0 -1
- package/docs/en/guides/topic-detail/module-federation/deploy.mdx +2 -2
- package/docs/en/guides/topic-detail/module-federation/introduce.mdx +0 -1
- package/docs/en/guides/upgrade/config.mdx +12 -0
- package/docs/en/guides/upgrade/other.mdx +4 -4
- package/docs/en/guides/upgrade/tailwindcss.mdx +0 -1
- package/docs/en/guides/upgrade/web-server.md +34 -17
- package/docs/en/index.md +1 -0
- package/docs/en/plugin/cli-plugins/api.mdx +23 -23
- package/docs/en/plugin/cli-plugins/life-cycle.mdx +2 -0
- package/docs/en/plugin/introduction.mdx +6 -6
- package/docs/en/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
- package/docs/en/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
- package/docs/en/plugin/plugin-system.mdx +19 -26
- package/docs/en/plugin/runtime-plugins/life-cycle.mdx +2 -0
- package/docs/en/plugin/server-plugins/api.mdx +11 -14
- package/docs/en/plugin/server-plugins/life-cycle.mdx +2 -0
- package/docs/zh/apis/app/hooks/api/lambda.mdx +1 -1
- package/docs/zh/apis/app/hooks/config/html.mdx +1 -0
- package/docs/zh/apis/app/hooks/config/mock.mdx +1 -0
- package/docs/zh/apis/app/hooks/config/public.mdx +1 -0
- package/docs/zh/apis/app/hooks/config/upload.mdx +2 -3
- package/docs/zh/apis/app/hooks/modern-config.mdx +1 -0
- package/docs/zh/apis/app/hooks/shared.mdx +1 -0
- package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +1 -0
- package/docs/zh/apis/app/hooks/src/routes.mdx +1 -0
- package/docs/zh/apis/app/hooks/src/server.mdx +2 -1
- package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +1 -1
- package/docs/zh/apis/app/runtime/core/create-root.mdx +4 -1
- package/docs/zh/apis/app/runtime/core/render.mdx +6 -3
- package/docs/zh/apis/app/runtime/core/runtime-context.mdx +17 -17
- package/docs/zh/apis/app/runtime/router/router.mdx +10 -6
- package/docs/zh/apis/app/runtime/ssr/no-ssr.mdx +1 -0
- package/docs/zh/apis/app/runtime/utility/head.mdx +1 -0
- package/docs/zh/apis/app/runtime/utility/loadable.mdx +1 -0
- package/docs/zh/community/blog/v3-release-note.mdx +38 -29
- package/docs/zh/community/contributing-guide.mdx +16 -34
- package/docs/zh/components/default-browserslist.mdx +0 -1
- package/docs/zh/components/deploy-command.mdx +1 -1
- package/docs/zh/components/deploy.mdx +1 -1
- package/docs/zh/components/entry-scan-logic.mdx +1 -1
- package/docs/zh/components/init-app.mdx +9 -3
- package/docs/zh/components/international/custom-instance-code.mdx +0 -1
- package/docs/zh/components/international/install-command.mdx +0 -1
- package/docs/zh/components/micro-runtime-config.mdx +12 -9
- package/docs/zh/components/nodeVersion.mdx +2 -2
- package/docs/zh/components/rsc-deploy-tip.mdx +0 -1
- package/docs/zh/components/ssr-monitor.mdx +1 -1
- package/docs/zh/configure/app/bff/cross-project.mdx +2 -2
- package/docs/zh/configure/app/bff/prefix.mdx +1 -1
- package/docs/zh/configure/app/dev/lazy-compilation.mdx +17 -1
- package/docs/zh/configure/app/html/crossorigin.mdx +0 -1
- package/docs/zh/configure/app/html/favicon.mdx +0 -1
- package/docs/zh/configure/app/output/convert-to-rem.mdx +0 -1
- package/docs/zh/configure/app/output/css-modules.mdx +1 -5
- package/docs/zh/configure/app/output/inline-scripts.mdx +1 -2
- package/docs/zh/configure/app/output/inline-styles.mdx +1 -2
- package/docs/zh/configure/app/output/source-map.mdx +0 -2
- package/docs/zh/configure/app/output/split-route-chunks.mdx +1 -1
- package/docs/zh/configure/app/output/ssg.mdx +1 -0
- package/docs/zh/configure/app/output/ssgByEntries.mdx +1 -1
- package/docs/zh/configure/app/performance/chunk-split.mdx +1 -4
- package/docs/zh/configure/app/resolve/dedupe.mdx +0 -1
- package/docs/zh/configure/app/runtime/plugins.mdx +6 -4
- package/docs/zh/configure/app/server/rsc.mdx +1 -1
- package/docs/zh/configure/app/server/ssr.mdx +6 -7
- package/docs/zh/configure/app/server/tsconfig-path.mdx +2 -2
- package/docs/zh/configure/app/tools/less.mdx +6 -7
- package/docs/zh/configure/app/tools/sass.mdx +6 -7
- package/docs/zh/configure/app/tools/svgr.mdx +11 -11
- package/docs/zh/configure/app/usage.mdx +1 -5
- package/docs/zh/guides/advanced-features/bff.mdx +1 -0
- package/docs/zh/guides/advanced-features/international/advanced.mdx +1 -1
- package/docs/zh/guides/advanced-features/international/api.mdx +28 -27
- package/docs/zh/guides/advanced-features/international/best-practices.mdx +15 -15
- package/docs/zh/guides/advanced-features/international/configuration.mdx +38 -36
- package/docs/zh/guides/advanced-features/international/locale-detection.mdx +37 -28
- package/docs/zh/guides/advanced-features/international/resource-loading.mdx +20 -16
- package/docs/zh/guides/advanced-features/international/routing.mdx +6 -4
- package/docs/zh/guides/advanced-features/international.mdx +9 -9
- package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +4 -6
- package/docs/zh/guides/advanced-features/server-monitor/metrics.mdx +9 -10
- package/docs/zh/guides/advanced-features/source-build.mdx +1 -1
- package/docs/zh/guides/advanced-features/web-server.mdx +3 -3
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +1 -3
- package/docs/zh/guides/basic-features/data/data-write.mdx +25 -31
- package/docs/zh/guides/basic-features/debug/mock.mdx +2 -2
- package/docs/zh/guides/basic-features/debug/using-storybook.mdx +5 -5
- package/docs/zh/guides/basic-features/env-vars.mdx +0 -1
- package/docs/zh/guides/basic-features/html.mdx +2 -3
- package/docs/zh/guides/basic-features/render/overview.mdx +12 -13
- package/docs/zh/guides/basic-features/render/rsc.mdx +16 -9
- package/docs/zh/guides/basic-features/render/ssr.mdx +8 -17
- package/docs/zh/guides/basic-features/routes/config-routes.mdx +61 -59
- package/docs/zh/guides/basic-features/testing/playwright.mdx +15 -10
- package/docs/zh/guides/basic-features/testing/rstest.mdx +6 -4
- package/docs/zh/guides/get-started/ai-coding-agents.mdx +7 -7
- package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +2 -2
- package/docs/zh/guides/upgrade/config.mdx +12 -0
- package/docs/zh/guides/upgrade/other.md +4 -11
- package/docs/zh/guides/upgrade/overview.mdx +1 -4
- package/docs/zh/guides/upgrade/tailwindcss.mdx +0 -1
- package/docs/zh/guides/upgrade/web-server.md +34 -19
- package/docs/zh/index.md +1 -0
- package/docs/zh/plugin/cli-plugins/api.mdx +24 -24
- package/docs/zh/plugin/cli-plugins/life-cycle.mdx +2 -0
- package/docs/zh/plugin/introduction.mdx +6 -6
- package/docs/zh/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
- package/docs/zh/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
- package/docs/zh/plugin/plugin-system.mdx +19 -26
- package/docs/zh/plugin/runtime-plugins/life-cycle.mdx +2 -0
- package/docs/zh/plugin/server-plugins/api.mdx +11 -14
- package/docs/zh/plugin/server-plugins/life-cycle.mdx +2 -0
- package/package.json +11 -13
- package/{rspress.config.ts → rstack.config.mts} +7 -10
- package/src/components/Footer/styles.module.scss +1 -1
- package/src/components/SolutionCards/index.module.scss +3 -1
|
@@ -21,7 +21,10 @@ These two approaches are mutually exclusive in the legacy version. When migratin
|
|
|
21
21
|
|
|
22
22
|
```typescript
|
|
23
23
|
// Legacy - server/index.ts
|
|
24
|
-
export const unstableMiddleware: UnstableMiddleware[] = [
|
|
24
|
+
export const unstableMiddleware: UnstableMiddleware[] = [
|
|
25
|
+
middleware1,
|
|
26
|
+
middleware2,
|
|
27
|
+
];
|
|
25
28
|
|
|
26
29
|
// New - server/modern.server.ts
|
|
27
30
|
import { defineServerConfig } from '@modern-js/server-runtime';
|
|
@@ -38,13 +41,22 @@ export default defineServerConfig({
|
|
|
38
41
|
|
|
39
42
|
```typescript
|
|
40
43
|
// Legacy
|
|
41
|
-
import type {
|
|
42
|
-
|
|
44
|
+
import type {
|
|
45
|
+
UnstableMiddleware,
|
|
46
|
+
UnstableMiddlewareContext,
|
|
47
|
+
} from '@modern-js/server-runtime';
|
|
48
|
+
const middleware: UnstableMiddleware = async (
|
|
49
|
+
c: UnstableMiddlewareContext,
|
|
50
|
+
next,
|
|
51
|
+
) => {
|
|
43
52
|
return c.response.raw('response'); // Will continue rendering even without calling next
|
|
44
53
|
};
|
|
45
54
|
|
|
46
55
|
// New
|
|
47
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
defineServerConfig,
|
|
58
|
+
type MiddlewareHandler,
|
|
59
|
+
} from '@modern-js/server-runtime';
|
|
48
60
|
const middleware: MiddlewareHandler = async (c, next) => {
|
|
49
61
|
await next(); // Must call
|
|
50
62
|
return c.text('response');
|
|
@@ -53,17 +65,17 @@ const middleware: MiddlewareHandler = async (c, next) => {
|
|
|
53
65
|
|
|
54
66
|
### Context API Comparison
|
|
55
67
|
|
|
56
|
-
| Legacy API
|
|
57
|
-
| -------------------- | ---------------------- |
|
|
58
|
-
| `c.request.cookie` | `getCookie(c, 'key')` | Cookie reading
|
|
59
|
-
| `c.req.cookie()` | `getCookie(c, 'key')` | Hono v4 deprecated
|
|
60
|
-
| `c.request.pathname` | `c.req.path` | Request path
|
|
61
|
-
| `c.request.host` | `c.req.header('Host')` | Request host
|
|
62
|
-
| `c.request.query` | `c.req.query()` | Query parameters
|
|
63
|
-
| `c.request.headers` | `c.req.header()` | Request headers
|
|
64
|
-
| `c.response.status` | `c.status()` | Response status code
|
|
65
|
-
| `c.response.set` | `c.res.headers.set` | Set response headers
|
|
66
|
-
| `c.response.raw` | `c.text` / `c.json` | Response body
|
|
68
|
+
| Legacy API | New API | Description |
|
|
69
|
+
| -------------------- | ---------------------- | -------------------- |
|
|
70
|
+
| `c.request.cookie` | `getCookie(c, 'key')` | Cookie reading |
|
|
71
|
+
| `c.req.cookie()` | `getCookie(c, 'key')` | Hono v4 deprecated |
|
|
72
|
+
| `c.request.pathname` | `c.req.path` | Request path |
|
|
73
|
+
| `c.request.host` | `c.req.header('Host')` | Request host |
|
|
74
|
+
| `c.request.query` | `c.req.query()` | Query parameters |
|
|
75
|
+
| `c.request.headers` | `c.req.header()` | Request headers |
|
|
76
|
+
| `c.response.status` | `c.status()` | Response status code |
|
|
77
|
+
| `c.response.set` | `c.res.headers.set` | Set response headers |
|
|
78
|
+
| `c.response.raw` | `c.text` / `c.json` | Response body |
|
|
67
79
|
|
|
68
80
|
## afterRender Hook
|
|
69
81
|
|
|
@@ -88,7 +100,10 @@ export const afterRender = (ctx, next) => {
|
|
|
88
100
|
};
|
|
89
101
|
|
|
90
102
|
// New - server/modern.server.ts
|
|
91
|
-
import {
|
|
103
|
+
import {
|
|
104
|
+
defineServerConfig,
|
|
105
|
+
type MiddlewareHandler,
|
|
106
|
+
} from '@modern-js/server-runtime';
|
|
92
107
|
|
|
93
108
|
const renderMiddleware: MiddlewareHandler = async (c, next) => {
|
|
94
109
|
await next(); // Wait for page rendering first
|
|
@@ -104,6 +119,8 @@ const renderMiddleware: MiddlewareHandler = async (c, next) => {
|
|
|
104
119
|
};
|
|
105
120
|
|
|
106
121
|
export default defineServerConfig({
|
|
107
|
-
renderMiddlewares: [
|
|
122
|
+
renderMiddlewares: [
|
|
123
|
+
{ name: 'custom-content-injection', handler: renderMiddleware },
|
|
124
|
+
],
|
|
108
125
|
});
|
|
109
126
|
```
|
package/docs/en/index.md
CHANGED
|
@@ -39,29 +39,29 @@ Gets the context information of the Modern.js application.
|
|
|
39
39
|
|
|
40
40
|
- **Returns:** An `AppContext` object containing the following fields:
|
|
41
41
|
|
|
42
|
-
| Field Name | Type | Description | When Available
|
|
43
|
-
| ---------------------- | ------------------- | ---------------------------------------------------------------- |
|
|
44
|
-
| `command` | `string` | The currently executing command (e.g., `dev`, `build`, `deploy`) | -
|
|
45
|
-
| `port` | `number` | The development server port number | After `onPrepare`
|
|
46
|
-
| `configFile` | `string` | The absolute path to the configuration file | -
|
|
47
|
-
| `isProd` | `boolean` | Whether it is in production mode | -
|
|
48
|
-
| `appDirectory` | `string` | The absolute path to the project root directory | -
|
|
49
|
-
| `srcDirectory` | `string` | The absolute path to the project source code directory | -
|
|
50
|
-
| `distDirectory` | `string` | The absolute path to the project output directory | In `onPrepare` (and later)
|
|
51
|
-
| `sharedDirectory` | `string` | The absolute path to the shared modules directory | -
|
|
52
|
-
| `nodeModulesDirectory` | `string` | The absolute path to the `node_modules` directory | -
|
|
53
|
-
| `ip` | `string` | The IPv4 address of the current machine | -
|
|
54
|
-
| `packageName` | `string` | The `name` field in the project's `package.json` | -
|
|
55
|
-
| `plugins` | `object[]` | The list of currently registered plugins | -
|
|
56
|
-
| `entrypoints` | `object[]` | Information about page entry points | -
|
|
57
|
-
| `serverRoutes` | `object[]` | Server-side routing information | -
|
|
58
|
-
| `bundlerType` | `webpack \| rspack` | The type of bundler currently in use (`webpack` or `rspack`) | After `onPrepare`
|
|
59
|
-
| `metaName` | `string` | The internal name of the framework | -
|
|
60
|
-
| `apiDirectory` | `string` | The absolute path to the API module directory (used by BFF) | -
|
|
61
|
-
| `lambdaDirectory` | `string` | The absolute path to the Lambda module directory (used by BFF) | -
|
|
62
|
-
| `runtimeConfigFile` | `string` | The name of the runtime configuration file | -
|
|
63
|
-
| `checkedEntries` | `string[]` | Specified entry information | -
|
|
64
|
-
| `apiOnly` | `boolean` | Whether it is in `apiOnly` mode | -
|
|
42
|
+
| Field Name | Type | Description | When Available |
|
|
43
|
+
| ---------------------- | ------------------- | ---------------------------------------------------------------- | -------------------------- |
|
|
44
|
+
| `command` | `string` | The currently executing command (e.g., `dev`, `build`, `deploy`) | - |
|
|
45
|
+
| `port` | `number` | The development server port number | After `onPrepare` |
|
|
46
|
+
| `configFile` | `string` | The absolute path to the configuration file | - |
|
|
47
|
+
| `isProd` | `boolean` | Whether it is in production mode | - |
|
|
48
|
+
| `appDirectory` | `string` | The absolute path to the project root directory | - |
|
|
49
|
+
| `srcDirectory` | `string` | The absolute path to the project source code directory | - |
|
|
50
|
+
| `distDirectory` | `string` | The absolute path to the project output directory | In `onPrepare` (and later) |
|
|
51
|
+
| `sharedDirectory` | `string` | The absolute path to the shared modules directory | - |
|
|
52
|
+
| `nodeModulesDirectory` | `string` | The absolute path to the `node_modules` directory | - |
|
|
53
|
+
| `ip` | `string` | The IPv4 address of the current machine | - |
|
|
54
|
+
| `packageName` | `string` | The `name` field in the project's `package.json` | - |
|
|
55
|
+
| `plugins` | `object[]` | The list of currently registered plugins | - |
|
|
56
|
+
| `entrypoints` | `object[]` | Information about page entry points | - |
|
|
57
|
+
| `serverRoutes` | `object[]` | Server-side routing information | - |
|
|
58
|
+
| `bundlerType` | `webpack \| rspack` | The type of bundler currently in use (`webpack` or `rspack`) | After `onPrepare` |
|
|
59
|
+
| `metaName` | `string` | The internal name of the framework | - |
|
|
60
|
+
| `apiDirectory` | `string` | The absolute path to the API module directory (used by BFF) | - |
|
|
61
|
+
| `lambdaDirectory` | `string` | The absolute path to the Lambda module directory (used by BFF) | - |
|
|
62
|
+
| `runtimeConfigFile` | `string` | The name of the runtime configuration file | - |
|
|
63
|
+
| `checkedEntries` | `string[]` | Specified entry information | - |
|
|
64
|
+
| `apiOnly` | `boolean` | Whether it is in `apiOnly` mode | - |
|
|
65
65
|
|
|
66
66
|
- **Example:**
|
|
67
67
|
|
|
@@ -126,12 +126,12 @@ You can read [Rsbuild Official Website - Plugins](https://v2.rsbuild.rs/plugins/
|
|
|
126
126
|
|
|
127
127
|
The following are official Rsbuild plugins that are already built into Modern.js. They can be enabled without installation:
|
|
128
128
|
|
|
129
|
-
| Plugin
|
|
130
|
-
|
|
|
131
|
-
| [React Plugin](https://v2.rsbuild.rs/plugins/list/plugin-react)
|
|
132
|
-
| [SVGR Plugin](https://v2.rsbuild.rs/plugins/list/plugin-svgr)
|
|
133
|
-
| [Assets Retry Plugin](https://github.com/rstackjs/rsbuild-plugin-assets-retry)
|
|
134
|
-
| [Type Check Plugin](https://github.com/rstackjs/rsbuild-plugin-type-check)
|
|
129
|
+
| Plugin | Description | Modern.js Link |
|
|
130
|
+
| -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
|
131
|
+
| [React Plugin](https://v2.rsbuild.rs/plugins/list/plugin-react) | Provides support for React | - |
|
|
132
|
+
| [SVGR Plugin](https://v2.rsbuild.rs/plugins/list/plugin-svgr) | Supports converting SVG images into React components | [tools.svgr](/configure/app/tools/svgr) |
|
|
133
|
+
| [Assets Retry Plugin](https://github.com/rstackjs/rsbuild-plugin-assets-retry) | Automatically retries requests when static asset loading fails | [output.assetsRetry](/configure/app/output/assets-retry.html) |
|
|
134
|
+
| [Type Check Plugin](https://github.com/rstackjs/rsbuild-plugin-type-check) | Runs TypeScript type checking in a separate process | [output.disableTsChecker](/configure/app/output/disable-ts-checker.html)<br />[tools.tsChecker](/configure/app/tools/ts-checker.html) |
|
|
135
135
|
| [Source Build Plugin](https://github.com/rstackjs/rsbuild-plugin-source-build) | For monorepo scenarios, supports referencing source code from other subdirectories and completing builds and hot updates | [experiments.sourceBuild](/configure/app/experiments/source-build.html) |
|
|
136
136
|
| [Check Syntax Plugin](https://github.com/rstackjs/rsbuild-plugin-check-syntax) | Analyzes the syntax compatibility of the build artifacts to determine if there are any advanced syntax features that cause compatibility issues | [security.checkSyntax](/configure/app/security/check-syntax.html) |
|
|
137
137
|
| [CSS Minimizer Plugin](https://github.com/rstackjs/rsbuild-plugin-css-minimizer) | Used to customize the CSS compression tool, switch to [cssnano](https://cssnano.co/) or other tools for CSS compression | [tools.minifyCss](/configure/app/tools/minify-css.html) |
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
In a Modern.js application, developers can define API files under the `api/lambda` directory and export API functions using the BFF plugin. In the frontend code, these API functions can be directly invoked by importing the file, which initiates the API requests.
|
|
4
4
|
|
|
5
|
-
For more details, refer to [BFF - Basic Usage](/guides/advanced-features/bff/function).
|
|
5
|
+
For more details, refer to [BFF - Basic Usage](/guides/advanced-features/bff/function).
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
SSG (Static Site Generation) is a technical solution that renders complete static web pages at build time based on data and templates. This means that in a production environment, pages are populated with content by default and can be cached by a CDN. For pages that do not require dynamic data, SSG can provide better performance and higher security.
|
|
4
4
|
|
|
5
|
-
For more details, refer to [Static Site Generation (SSG)](/guides/basic-features/render/ssg).
|
|
5
|
+
For more details, refer to [Static Site Generation (SSG)](/guides/basic-features/render/ssg).
|
|
@@ -16,31 +16,26 @@ Modern.js adheres to the design philosophy of "everything is a plugin," modulari
|
|
|
16
16
|
Modern.js provides three main plugin types, corresponding to different stages of application development:
|
|
17
17
|
|
|
18
18
|
**CLI Plugins:**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
|
|
20
|
+
- **Active Stage:** Build time (when executing the `modern` command).
|
|
21
|
+
- **Typical Scenarios:**
|
|
22
|
+
- Extending command-line tools.
|
|
23
|
+
- Modifying build configurations.
|
|
24
|
+
- Listening for file changes.
|
|
25
|
+
- Controlling the build process.
|
|
26
|
+
- **Configuration Method:** The `plugins` field in `modern.config.ts`.
|
|
26
27
|
|
|
27
28
|
**Runtime Plugins:**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- **Typical Scenarios:**
|
|
39
|
-
- Adding custom middleware.
|
|
40
|
-
- Extending server-side APIs.
|
|
41
|
-
- Customizing SSR logic.
|
|
42
|
-
- Integrating with backend frameworks.
|
|
43
|
-
- **Configuration Method:** The `plugins` field in `server/modern.server.ts`. */}
|
|
29
|
+
|
|
30
|
+
- **Active Stage:** Application runtime (browser/Node.js environment).
|
|
31
|
+
- **Typical Scenarios:**
|
|
32
|
+
- Initializing global state or services.
|
|
33
|
+
- Encapsulating React Higher-Order Components (HOCs).
|
|
34
|
+
- Intercepting or modifying routing behavior.
|
|
35
|
+
- Controlling the rendering process.
|
|
36
|
+
- **Configuration Method:** The `plugins` field in `src/modern.runtime.ts`.
|
|
37
|
+
|
|
38
|
+
{/* **Server Plugins:** - **Active Stage:** Server request processing stage. - **Typical Scenarios:** - Adding custom middleware. - Extending server-side APIs. - Customizing SSR logic. - Integrating with backend frameworks. - **Configuration Method:** The `plugins` field in `server/modern.server.ts`. */}
|
|
44
39
|
|
|
45
40
|
## Plugin Structure
|
|
46
41
|
|
|
@@ -196,9 +191,7 @@ Example:
|
|
|
196
191
|
// Define Hooks
|
|
197
192
|
import { createSyncHook } from '@modern-js/plugin';
|
|
198
193
|
|
|
199
|
-
type RouteObject = {
|
|
200
|
-
/** TODO **/
|
|
201
|
-
};
|
|
194
|
+
type RouteObject = {/** TODO **/};
|
|
202
195
|
const modifyRoutes = createSyncHook<(routes: RouteObject[]) => RouteObject[]>();
|
|
203
196
|
|
|
204
197
|
// Register Hooks in the plugin
|
|
@@ -46,17 +46,17 @@ Gets the context information of the Modern.js server.
|
|
|
46
46
|
|
|
47
47
|
- **Returns:** A `ServerContext` object containing the following fields:
|
|
48
48
|
|
|
49
|
-
| Field Name | Type | Description
|
|
50
|
-
| ------------------- | ----------------- |
|
|
51
|
-
| `middlewares` | `MiddlewareObj[]` | Middleware list
|
|
52
|
-
| `renderMiddlewares` | `MiddlewareObj[]` | Render middleware list
|
|
53
|
-
| `routes` | `ServerRoute[]` | Server routing information
|
|
54
|
-
| `appDirectory` | `string` | Absolute path to the project root
|
|
55
|
-
| `apiDirectory` | `string` | Absolute path to the API module dir
|
|
56
|
-
| `lambdaDirectory` | `string` | Absolute path to the Lambda module dir|
|
|
57
|
-
| `sharedDirectory` | `string` | Absolute path to the shared module dir|
|
|
58
|
-
| `distDirectory` | `string` | Absolute path to the output directory|
|
|
59
|
-
| `plugins`
|
|
49
|
+
| Field Name | Type | Description |
|
|
50
|
+
| ------------------- | ----------------- | -------------------------------------- |
|
|
51
|
+
| `middlewares` | `MiddlewareObj[]` | Middleware list |
|
|
52
|
+
| `renderMiddlewares` | `MiddlewareObj[]` | Render middleware list |
|
|
53
|
+
| `routes` | `ServerRoute[]` | Server routing information |
|
|
54
|
+
| `appDirectory` | `string` | Absolute path to the project root |
|
|
55
|
+
| `apiDirectory` | `string` | Absolute path to the API module dir |
|
|
56
|
+
| `lambdaDirectory` | `string` | Absolute path to the Lambda module dir |
|
|
57
|
+
| `sharedDirectory` | `string` | Absolute path to the shared module dir |
|
|
58
|
+
| `distDirectory` | `string` | Absolute path to the output directory |
|
|
59
|
+
| `plugins` | `ServerPlugin[]` | List of currently registered plugins |
|
|
60
60
|
|
|
61
61
|
- **Example:**
|
|
62
62
|
|
|
@@ -111,7 +111,6 @@ In custom plugins, you can only manually call the hooks registered by the corres
|
|
|
111
111
|
|
|
112
112
|
---
|
|
113
113
|
|
|
114
|
-
|
|
115
114
|
## Context Modification
|
|
116
115
|
|
|
117
116
|
#### `api.updateServerContext`
|
|
@@ -143,7 +142,6 @@ api.onPrepare(() => {
|
|
|
143
142
|
|
|
144
143
|
---
|
|
145
144
|
|
|
146
|
-
|
|
147
145
|
## Lifecycle Hooks
|
|
148
146
|
|
|
149
147
|
#### `api.onPrepare`
|
|
@@ -205,7 +203,6 @@ api.onReset(async ({ event }) => {
|
|
|
205
203
|
|
|
206
204
|
---
|
|
207
205
|
|
|
208
|
-
|
|
209
206
|
## Other Notes
|
|
210
207
|
|
|
211
208
|
- Refer to [Server Plugin Lifecycle](./life-cycle.mdx) to understand the execution order of plugin hooks.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
title: upload/
|
|
3
3
|
sidebar_position: 4
|
|
4
4
|
---
|
|
5
|
+
|
|
5
6
|
# upload/
|
|
6
7
|
|
|
7
8
|
`upload/` 目录中可以放置任意格式的静态资源文件。
|
|
@@ -30,9 +31,7 @@ sidebar_position: 4
|
|
|
30
31
|
|
|
31
32
|
```tsx
|
|
32
33
|
export default () => {
|
|
33
|
-
return
|
|
34
|
-
<img src={`${process.env.ASSET_PREFIX}/upload/banner.png`}></img>
|
|
35
|
-
);
|
|
34
|
+
return <img src={`${process.env.ASSET_PREFIX}/upload/banner.png`}></img>;
|
|
36
35
|
};
|
|
37
36
|
```
|
|
38
37
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: createRoot
|
|
3
3
|
---
|
|
4
|
+
|
|
4
5
|
# createRoot
|
|
5
6
|
|
|
6
7
|
用于创建 Modern.js 提供的根组件,该根组件会自动注册 Runtime 插件,并完成 Runtime 插件初始化。
|
|
@@ -14,7 +15,9 @@ import { createRoot } from '@modern-js/runtime/react';
|
|
|
14
15
|
## 函数签名
|
|
15
16
|
|
|
16
17
|
```ts
|
|
17
|
-
export function createRoot(
|
|
18
|
+
export function createRoot(
|
|
19
|
+
UserApp?: React.ComponentType | null,
|
|
20
|
+
): React.ComponentType<any>;
|
|
18
21
|
```
|
|
19
22
|
|
|
20
23
|
### 参数
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: render
|
|
3
3
|
---
|
|
4
|
+
|
|
4
5
|
# render
|
|
5
6
|
|
|
6
7
|
用于渲染项目组件。
|
|
@@ -16,7 +17,10 @@ render(<ModernRoot />);
|
|
|
16
17
|
## 函数签名
|
|
17
18
|
|
|
18
19
|
```ts
|
|
19
|
-
export function render(
|
|
20
|
+
export function render(
|
|
21
|
+
App: React.ReactElement,
|
|
22
|
+
id?: HTMLElement | string,
|
|
23
|
+
): Promise<any>;
|
|
20
24
|
```
|
|
21
25
|
|
|
22
26
|
### 参数
|
|
@@ -33,11 +37,10 @@ import { render } from '@modern-js/runtime/browser';
|
|
|
33
37
|
const ModernRoot = createRoot();
|
|
34
38
|
|
|
35
39
|
async function beforeRender() {
|
|
36
|
-
|
|
40
|
+
// todo
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
beforeRender().then(() => {
|
|
40
44
|
render(<ModernRoot />);
|
|
41
45
|
});
|
|
42
46
|
```
|
|
43
|
-
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: RuntimeContext
|
|
3
3
|
---
|
|
4
|
+
|
|
4
5
|
# RuntimeContext
|
|
5
6
|
|
|
6
7
|
`RuntimeContext` 是一个 React Context,用于在组件中获取 Runtime 上下文信息。该 Context 可以通过 React 的 `use` 或 `useContext` API 访问。
|
|
@@ -19,7 +20,7 @@ import { RuntimeContext } from '@modern-js/runtime';
|
|
|
19
20
|
|
|
20
21
|
export function App() {
|
|
21
22
|
const runtimeContext = use(RuntimeContext); // 也可以使用 useContext(RuntimeContext)
|
|
22
|
-
return <div>Hello World</div
|
|
23
|
+
return <div>Hello World</div>;
|
|
23
24
|
}
|
|
24
25
|
```
|
|
25
26
|
|
|
@@ -53,21 +54,21 @@ type TRuntimeContext = {
|
|
|
53
54
|
```ts
|
|
54
55
|
type RequestContext = {
|
|
55
56
|
request: {
|
|
56
|
-
params: Record<string, string>;
|
|
57
|
-
pathname: string;
|
|
58
|
-
query: Record<string, string>;
|
|
59
|
-
headers: IncomingHttpHeaders;
|
|
60
|
-
host: string;
|
|
61
|
-
url: string;
|
|
62
|
-
referer?: string;
|
|
63
|
-
userAgent?: string;
|
|
64
|
-
cookie?: string;
|
|
65
|
-
cookieMap?: Record<string, string>;
|
|
57
|
+
params: Record<string, string>; // 路由参数
|
|
58
|
+
pathname: string; // 路径名
|
|
59
|
+
query: Record<string, string>; // 查询参数
|
|
60
|
+
headers: IncomingHttpHeaders; // 请求头
|
|
61
|
+
host: string; // 主机名
|
|
62
|
+
url: string; // 完整 URL
|
|
63
|
+
referer?: string; // 来源页面
|
|
64
|
+
userAgent?: string; // 用户代理
|
|
65
|
+
cookie?: string; // Cookie 字符串
|
|
66
|
+
cookieMap?: Record<string, string>; // Cookie 映射对象
|
|
66
67
|
};
|
|
67
68
|
response: {
|
|
68
|
-
setHeader: (key: string, value: string) => void;
|
|
69
|
-
status: (code: number) => void;
|
|
70
|
-
locals: Record<string, any>;
|
|
69
|
+
setHeader: (key: string, value: string) => void; // 设置响应头(仅服务端)
|
|
70
|
+
status: (code: number) => void; // 设置状态码(仅服务端)
|
|
71
|
+
locals: Record<string, any>; // 本地数据
|
|
71
72
|
};
|
|
72
73
|
};
|
|
73
74
|
```
|
|
@@ -91,11 +92,11 @@ function App() {
|
|
|
91
92
|
|
|
92
93
|
if (isBrowser === true) {
|
|
93
94
|
// 浏览器端执行逻辑
|
|
94
|
-
console.log('browser render')
|
|
95
|
+
console.log('browser render');
|
|
95
96
|
} else {
|
|
96
97
|
// 服务器端执行逻辑
|
|
97
98
|
// 注意:logger 等功能需要通过 Runtime 插件注入到 context 中
|
|
98
|
-
console.log('server render')
|
|
99
|
+
console.log('server render');
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
```
|
|
@@ -157,4 +158,3 @@ export default function MyComponent() {
|
|
|
157
158
|
return <div>{message}</div>;
|
|
158
159
|
}
|
|
159
160
|
```
|
|
160
|
-
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
title: router
|
|
3
3
|
sidebar_position: 1
|
|
4
4
|
---
|
|
5
|
+
|
|
5
6
|
# router
|
|
6
7
|
|
|
7
8
|
:::info 补充信息
|
|
@@ -135,8 +136,10 @@ export default ErrorBoundary;
|
|
|
135
136
|
```ts
|
|
136
137
|
declare function Link(props: LinkProps): React.ReactElement;
|
|
137
138
|
|
|
138
|
-
interface LinkProps
|
|
139
|
-
|
|
139
|
+
interface LinkProps extends Omit<
|
|
140
|
+
React.AnchorHTMLAttributes<HTMLAnchorElement>,
|
|
141
|
+
'href'
|
|
142
|
+
> {
|
|
140
143
|
replace?: boolean;
|
|
141
144
|
state?: any;
|
|
142
145
|
to: To;
|
|
@@ -157,12 +160,13 @@ type To = string | Partial<Path>;
|
|
|
157
160
|
```ts
|
|
158
161
|
declare function NavLink(props: NavLinkProps): React.ReactElement;
|
|
159
162
|
|
|
160
|
-
interface NavLinkProps
|
|
161
|
-
|
|
163
|
+
interface NavLinkProps extends Omit<
|
|
164
|
+
LinkProps,
|
|
165
|
+
'className' | 'style' | 'children'
|
|
166
|
+
> {
|
|
162
167
|
caseSensitive?: boolean;
|
|
163
168
|
children?:
|
|
164
|
-
| React.ReactNode
|
|
165
|
-
| ((props: { isActive: boolean }) => React.ReactNode);
|
|
169
|
+
React.ReactNode | ((props: { isActive: boolean }) => React.ReactNode);
|
|
166
170
|
className?: string | ((props: { isActive: boolean }) => string | undefined);
|
|
167
171
|
end?: boolean;
|
|
168
172
|
style?:
|