@modern-js/main-doc 3.0.0-alpha.0 → 3.0.0-alpha.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.
Files changed (142) hide show
  1. package/docs/en/apis/app/commands.mdx +6 -30
  2. package/docs/en/components/bff-upload.mdx +3 -5
  3. package/docs/en/components/bundler.mdx +1 -1
  4. package/docs/en/components/enable-bff.mdx +6 -2
  5. package/docs/en/components/enable-ssg.mdx +1 -0
  6. package/docs/en/components/esbuild.mdx +2 -2
  7. package/docs/en/components/extend-bff-function.mdx +2 -4
  8. package/docs/en/components/hono.mdx +119 -0
  9. package/docs/en/components/international/custom-instance-code.mdx +16 -0
  10. package/docs/en/components/international/init-options-desc.mdx +1 -0
  11. package/docs/en/components/international/install-command.mdx +15 -1
  12. package/docs/en/components/international/instance-code.mdx +26 -0
  13. package/docs/en/configure/app/builder-plugins.mdx +1 -2
  14. package/docs/en/configure/app/dev/server.mdx +108 -0
  15. package/docs/en/configure/app/experiments/source-build.mdx +0 -1
  16. package/docs/en/configure/app/output/assets-retry.mdx +1 -1
  17. package/docs/en/configure/app/output/disable-inline-runtime-chunk.mdx +2 -2
  18. package/docs/en/configure/app/output/filename.mdx +2 -4
  19. package/docs/en/configure/app/output/temp-dir.mdx +3 -3
  20. package/docs/en/configure/app/performance/build-cache.mdx +1 -1
  21. package/docs/en/configure/app/performance/profile.mdx +1 -1
  22. package/docs/en/configure/app/plugins.mdx +1 -3
  23. package/docs/en/configure/app/runtime/router.mdx +0 -4
  24. package/docs/en/configure/app/security/sri.mdx +0 -1
  25. package/docs/en/configure/app/source/alias.mdx +1 -1
  26. package/docs/en/configure/app/source/enable-async-entry.mdx +1 -1
  27. package/docs/en/configure/app/source/include.mdx +2 -14
  28. package/docs/en/configure/app/tools/dev-server.mdx +8 -8
  29. package/docs/en/configure/app/usage.mdx +0 -12
  30. package/docs/en/guides/_meta.json +5 -0
  31. package/docs/en/guides/advanced-features/bff/_meta.json +9 -1
  32. package/docs/en/guides/advanced-features/bff/cross-project.mdx +1 -1
  33. package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -15
  34. package/docs/en/guides/advanced-features/bff/function.mdx +4 -4
  35. package/docs/en/guides/advanced-features/bff/operators.mdx +628 -0
  36. package/docs/en/guides/advanced-features/bff/sdk.mdx +17 -9
  37. package/docs/en/guides/advanced-features/bff/upload.mdx +3 -1
  38. package/docs/en/guides/advanced-features/international/configuration.mdx +7 -16
  39. package/docs/en/guides/advanced-features/international/quick-start.mdx +4 -32
  40. package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +1 -1
  41. package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +18 -4
  42. package/docs/en/guides/advanced-features/rspack-start.mdx +1 -1
  43. package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +62 -5
  44. package/docs/en/guides/basic-features/data/data-cache.mdx +60 -76
  45. package/docs/en/guides/basic-features/data/data-fetch.mdx +15 -14
  46. package/docs/en/guides/basic-features/debug/proxy.mdx +6 -9
  47. package/docs/en/guides/basic-features/render/rsc.mdx +24 -19
  48. package/docs/en/guides/basic-features/render/ssg.mdx +4 -9
  49. package/docs/en/guides/basic-features/render/ssr-cache.mdx +0 -4
  50. package/docs/en/guides/basic-features/static-assets/svg-assets.mdx +0 -4
  51. package/docs/en/guides/get-started/tech-stack.mdx +1 -1
  52. package/docs/en/guides/upgrade/_meta.json +1 -0
  53. package/docs/en/guides/upgrade/config.mdx +936 -0
  54. package/docs/en/guides/upgrade/entry.mdx +463 -0
  55. package/docs/en/guides/upgrade/other.mdx +83 -0
  56. package/docs/en/guides/upgrade/overview.mdx +33 -0
  57. package/docs/en/guides/upgrade/tailwindcss.mdx +130 -0
  58. package/docs/en/guides/upgrade/web-server.mdx +91 -0
  59. package/docs/en/plugin/_meta.json +5 -0
  60. package/docs/en/plugin/cli-plugins/_meta.json +1 -1
  61. package/docs/en/plugin/cli-plugins/api.mdx +13 -63
  62. package/docs/en/plugin/cli-plugins/life-cycle.mdx +0 -4
  63. package/docs/en/plugin/introduction.mdx +8 -20
  64. package/docs/en/plugin/plugin-system.mdx +3 -3
  65. package/docs/en/plugin/runtime-plugins/_meta.json +1 -1
  66. package/docs/en/plugin/runtime-plugins/api.mdx +1 -1
  67. package/docs/en/plugin/server-plugins/_meta.json +1 -0
  68. package/docs/en/plugin/server-plugins/api.mdx +210 -1
  69. package/docs/en/plugin/server-plugins/life-cycle.mdx +41 -1
  70. package/docs/zh/apis/app/commands.mdx +6 -30
  71. package/docs/zh/components/bff-operator-code.mdx +5 -0
  72. package/docs/zh/components/bff-upload.mdx +0 -2
  73. package/docs/zh/components/bundler.mdx +1 -1
  74. package/docs/zh/components/enable-bff.mdx +6 -2
  75. package/docs/zh/components/enable-ssg.mdx +3 -1
  76. package/docs/zh/components/esbuild.mdx +2 -2
  77. package/docs/zh/components/extend-bff-function.mdx +2 -4
  78. package/docs/zh/components/hono.mdx +119 -0
  79. package/docs/zh/components/international/custom-instance-code.mdx +16 -0
  80. package/docs/zh/components/international/init-options-desc.mdx +1 -0
  81. package/docs/zh/components/international/install-command.mdx +15 -0
  82. package/docs/zh/components/international/instance-code.mdx +26 -0
  83. package/docs/zh/configure/app/builder-plugins.mdx +1 -2
  84. package/docs/zh/configure/app/dev/server.mdx +109 -2
  85. package/docs/zh/configure/app/experiments/source-build.mdx +0 -1
  86. package/docs/zh/configure/app/output/assets-retry.mdx +1 -1
  87. package/docs/zh/configure/app/output/disable-inline-runtime-chunk.mdx +2 -2
  88. package/docs/zh/configure/app/output/filename.mdx +2 -4
  89. package/docs/zh/configure/app/output/temp-dir.mdx +3 -3
  90. package/docs/zh/configure/app/performance/build-cache.mdx +1 -1
  91. package/docs/zh/configure/app/performance/profile.mdx +1 -1
  92. package/docs/zh/configure/app/plugins.mdx +1 -2
  93. package/docs/zh/configure/app/runtime/router.mdx +0 -4
  94. package/docs/zh/configure/app/security/sri.mdx +0 -1
  95. package/docs/zh/configure/app/source/alias.mdx +1 -1
  96. package/docs/zh/configure/app/source/enable-async-entry.mdx +1 -1
  97. package/docs/zh/configure/app/source/include.mdx +2 -16
  98. package/docs/zh/configure/app/tools/dev-server.mdx +5 -5
  99. package/docs/zh/configure/app/usage.mdx +0 -12
  100. package/docs/zh/guides/advanced-features/bff/_meta.json +9 -1
  101. package/docs/zh/guides/advanced-features/bff/frameworks.mdx +2 -16
  102. package/docs/zh/guides/advanced-features/bff/operators.mdx +628 -0
  103. package/docs/zh/guides/advanced-features/bff/sdk.mdx +19 -12
  104. package/docs/zh/guides/advanced-features/bff/upload.mdx +3 -1
  105. package/docs/zh/guides/advanced-features/international/configuration.mdx +7 -16
  106. package/docs/zh/guides/advanced-features/international/quick-start.mdx +2 -25
  107. package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +1 -1
  108. package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +18 -4
  109. package/docs/zh/guides/advanced-features/server-monitor/monitors.mdx +60 -5
  110. package/docs/zh/guides/basic-features/data/data-cache.mdx +47 -54
  111. package/docs/zh/guides/basic-features/data/data-fetch.mdx +9 -12
  112. package/docs/zh/guides/basic-features/debug/proxy.mdx +4 -7
  113. package/docs/zh/guides/basic-features/render/rsc.mdx +23 -37
  114. package/docs/zh/guides/basic-features/render/ssr-cache.mdx +0 -4
  115. package/docs/zh/guides/basic-features/static-assets/svg-assets.mdx +0 -4
  116. package/docs/zh/guides/get-started/tech-stack.mdx +1 -1
  117. package/docs/zh/guides/troubleshooting/builder.mdx +1 -1
  118. package/docs/zh/guides/upgrade/config.mdx +132 -1
  119. package/docs/zh/plugin/_meta.json +5 -0
  120. package/docs/zh/plugin/cli-plugins/_meta.json +1 -1
  121. package/docs/zh/plugin/cli-plugins/api.mdx +15 -65
  122. package/docs/zh/plugin/cli-plugins/life-cycle.mdx +0 -4
  123. package/docs/zh/plugin/introduction.mdx +4 -16
  124. package/docs/zh/plugin/plugin-system.mdx +3 -14
  125. package/docs/zh/plugin/runtime-plugins/_meta.json +1 -1
  126. package/docs/zh/plugin/runtime-plugins/api.mdx +1 -1
  127. package/docs/zh/plugin/server-plugins/_meta.json +1 -0
  128. package/docs/zh/plugin/server-plugins/api.mdx +210 -1
  129. package/docs/zh/plugin/server-plugins/life-cycle.mdx +41 -1
  130. package/package.json +2 -2
  131. package/src/components/FrameworkCode/index.tsx +605 -0
  132. package/docs/en/configure/app/performance/bundle-analyze.mdx +0 -24
  133. package/docs/en/configure/app/tools/babel.mdx +0 -225
  134. package/docs/en/plugin/cli-plugins/migration.mdx +0 -83
  135. package/docs/en/plugin/runtime-plugins/migration.mdx +0 -110
  136. package/docs/zh/components/default-mwa-generate.mdx +0 -4
  137. package/docs/zh/configure/app/performance/bundle-analyze.mdx +0 -24
  138. package/docs/zh/configure/app/tools/babel.mdx +0 -224
  139. package/docs/zh/plugin/cli-plugins/migration.mdx +0 -83
  140. package/docs/zh/plugin/runtime-plugins/migration.mdx +0 -110
  141. /package/docs/en/components/{router-legacy-tip.mdx → upgrade-config-deploy.mdx} +0 -0
  142. /package/docs/zh/components/{router-legacy-tip.mdx → upgrade-config-deploy.mdx} +0 -0
@@ -4,27 +4,24 @@ sidebar_position: 6
4
4
 
5
5
  # Network Proxy
6
6
 
7
- Modern.js provides a way to configure the development proxy in [`tools.devServer`](/configure/app/tools/dev-server). For example, to proxy the local interface to an online address:
7
+ Modern.js provides a way to configure the development proxy in [`dev.server.proxy`](/configure/app/dev/server). For example, to proxy the local interface to an online address:
8
8
 
9
9
  ```ts title="modern.config.ts"
10
10
  import { defineConfig } from '@modern-js/app-tools';
11
11
 
12
12
  export default defineConfig({
13
- tools: {
14
- devServer: {
13
+ dev: {
14
+ server: {
15
15
  proxy: {
16
- '/go/api': {
17
- target: 'http://www.example.com/',
18
- changeOrigin: true,
19
- },
16
+ '/go/api': 'http://www.example.com/',
20
17
  },
21
18
  },
22
19
  },
23
20
  });
24
21
  ```
25
22
 
26
- When access `http://localhost:8080/go/api`, the response content will be returned from [http://www.example.com/](http://www.example.com/).
23
+ When accessing `http://localhost:8080/go/api`, the response content will be returned from [http://www.example.com/](http://www.example.com/).
27
24
 
28
25
  :::info
29
- For more detail, see [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware).
26
+ For configuration format, please refer to: [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware).
30
27
  :::
@@ -30,6 +30,7 @@ npm install react-server-dom-webpack
30
30
  ```
31
31
 
32
32
  :::warning Notes
33
+
33
34
  1. Currently, [Server Functions](https://react.dev/reference/rsc/server-functions) are not supported in SPA projects
34
35
  2. Currently, when building with Rspack, the output chunks and bundle size are not yet optimal. We will further optimize this in the near future
35
36
 
@@ -90,7 +91,7 @@ The `"use client"` directive creates a boundary: all code within the boundary wi
90
91
  :::
91
92
 
92
93
  ```tsx title="components/InteractiveCard.tsx"
93
- "use client"; // <--- This is where the Client Boundary starts
94
+ 'use client'; // <--- This is where the Client Boundary starts
94
95
 
95
96
  import { useState } from 'react';
96
97
  import Button from './Button'; // Button.tsx doesn't have "use client", but will be included in the client bundle
@@ -142,7 +143,7 @@ export default async function Page() {
142
143
  ```
143
144
 
144
145
  ```tsx title="routes/CounterButton.tsx"
145
- "use client"; // Client Component
146
+ 'use client'; // Client Component
146
147
 
147
148
  import { useState } from 'react';
148
149
 
@@ -163,7 +164,7 @@ However, there are two patterns to work around this limitation:
163
164
  You can pass Server Components as the `children` Prop to a Client Component. For example, an animated Tabs component where the tab switching logic is client-side, but the content of each tab might be static and fetched from the server.
164
165
 
165
166
  ```tsx title="app/components/Tabs.tsx"
166
- "use client"; // Client Component
167
+ 'use client'; // Client Component
167
168
 
168
169
  import React, { useState } from 'react';
169
170
 
@@ -198,7 +199,7 @@ import Analytics from '../components/Analytics'; // Server Component
198
199
  import UserSettings from '../components/UserSettings'; // Server Component
199
200
 
200
201
  export default function DashboardPage() {
201
- const labels = ["Analytics", "Settings"];
202
+ const labels = ['Analytics', 'Settings'];
202
203
 
203
204
  return (
204
205
  <main>
@@ -225,9 +226,9 @@ Through this pattern, you can keep components on the server to the maximum exten
225
226
  Each level of route components (such as `layout.tsx`, `page.tsx`) can independently choose to be a Client Component or Server Component:
226
227
 
227
228
  ```ts
228
- - routes
229
- - layout.tsx // Can be a Client Component
230
- - page.tsx // Can be a Server Component
229
+ -routes -
230
+ layout.tsx - // Can be a Client Component
231
+ page.tsx; // Can be a Server Component
231
232
  ```
232
233
 
233
234
  For example, if `layout.tsx` is a Client Component (requiring client-side interactivity), you can still set `page.tsx` as a Server Component (for data fetching and rendering). This approach provides great flexibility and allows non-RSC projects to gradually migrate to RSC projects.
@@ -250,33 +251,33 @@ function NonCriticalUI({ p }: { p: Promise<string> }) {
250
251
 
251
252
  <React.Suspense fallback={<div>Loading...</div>}>
252
253
  <NonCriticalUI p={nonCriticalData} />
253
- </React.Suspense>
254
+ </React.Suspense>;
254
255
  ```
255
256
 
256
257
  ## Best Practices
257
258
 
258
259
  ### Data Fetching
259
260
 
260
- 1. Whether it's an SSR or RSC project, it's recommended to use the `cache` function provided by edenx for data fetching logic executed on the server by default. This ensures that for each server-side render, no matter how many times the function is called, it will only execute once.
261
+ 1. Whether it's an SSR or RSC project, it's recommended to use the `cache` function provided by EdenX for data fetching logic executed on the server by default. This ensures that for each server-side render, no matter how many times the function is called, it will only execute once.
261
262
 
262
- > This is also the recommended usage by React.js, which provides the [cache](https://react.dev/reference/react/cache) function. EdenX's [cache](https://edenx.bytedance.net/guides/basic-features/data/data-cache.html) can be considered a superset of it.
263
+ > This is also the recommended usage by React.js, which provides the [cache](https://react.dev/reference/react/cache) function. EdenX's [cache](/guides/basic-features/data/data-cache.html) can be considered a superset of it.
263
264
 
264
265
  ```typescript
265
- import { cache } from '@edenx/runtime/cache'
266
+ import { cache } from '@modern-js/runtime/cache';
266
267
 
267
268
  const getCriticalCached = cache(getCritical);
268
269
  ```
269
270
 
270
- * Based on using the `cache` function, you no longer need to manage server-side state through `props`, `context`, etc. We recommend fetching data in the nearest Server Component where it's needed. With the `cache` function, even if the same function is called multiple times, this makes project state management, business logic, and performance optimization simpler.
271
+ - Based on using the `cache` function, you no longer need to manage server-side state through `props`, `context`, etc. We recommend fetching data in the nearest Server Component where it's needed. With the `cache` function, even if the same function is called multiple times, this makes project state management, business logic, and performance optimization simpler.
271
272
 
272
273
  ```typescript
273
274
  // layout.tsx
274
- export default async function Layout(){
275
- const criticalData = await getCriticalCached();
275
+ export default async function Layout() {
276
+ const criticalData = await getCriticalCached();
276
277
  }
277
278
 
278
- export default async function Page(){
279
- const criticalData = await getCriticalCached();
279
+ export default async function Page() {
280
+ const criticalData = await getCriticalCached();
280
281
  }
281
282
  ```
282
283
 
@@ -295,7 +296,9 @@ export default async function PostsList() {
295
296
 
296
297
  return (
297
298
  <ul>
298
- {posts.map(post => <li key={post.id}>{post.title}</li>)}
299
+ {posts.map(post => (
300
+ <li key={post.id}>{post.title}</li>
301
+ ))}
299
302
  </ul>
300
303
  );
301
304
  }
@@ -332,13 +335,15 @@ There's another scenario where data is consumed in Client Components. In this ca
332
335
 
333
336
  ```javascript
334
337
  // profile/components/PostsList.tsx
335
- 'use client'
338
+ 'use client';
336
339
  export default function PostsList({ postsPromise }) {
337
340
  const posts = use(postsPromise);
338
341
 
339
342
  return (
340
343
  <ul>
341
- {posts.map(post => <li key={post.id}>{post.title}</li>)}
344
+ {posts.map(post => (
345
+ <li key={post.id}>{post.title}</li>
346
+ ))}
342
347
  </ul>
343
348
  );
344
349
  }
@@ -7,7 +7,7 @@ SSG (Static Site Generation) is a technical solution that generates complete sta
7
7
 
8
8
  ## Enabling SSG
9
9
 
10
- import EnableSSG from "@site-docs-en/components/enable-ssg";
10
+ import EnableSSG from '@site-docs-en/components/enable-ssg';
11
11
 
12
12
  <EnableSSG />
13
13
 
@@ -70,7 +70,6 @@ Each route in **conventional routing** will generate a separate HTML file. Check
70
70
 
71
71
  After running `pnpm run serve` to start the project, inspect the returned document in the Network tab of the browser's development tools. The document includes the fully rendered content from the component.
72
72
 
73
-
74
73
  ## Using SSG in Manual Routing
75
74
 
76
75
  **Manual routing** defines routes through component code, requiring the application to run to obtain accurate route information. Therefore, you cannot use the SSG feature out of the box. Developers need to configure which routes require SSG.
@@ -109,11 +108,7 @@ In manual routing or conventional routing with dynamic segments (e.g., `/user/[i
109
108
  export default defineConfig({
110
109
  output: {
111
110
  ssg: {
112
- routes: [
113
- '/',
114
- '/about',
115
- '/user/modernjs',
116
- ],
111
+ routes: ['/', '/about', '/user/modernjs'],
117
112
  },
118
113
  },
119
114
  });
@@ -149,14 +144,14 @@ export default defineConfig({
149
144
  output: {
150
145
  ssg: {
151
146
  headers: {
152
- "x-tt-env": "ppe_modernjs"
147
+ 'x-tt-env': 'ppe_modernjs',
153
148
  },
154
149
  routes: [
155
150
  '/',
156
151
  {
157
152
  url: '/about',
158
153
  headers: {
159
- "from": "modern-website"
154
+ from: 'modern-website',
160
155
  },
161
156
  },
162
157
  ],
@@ -4,10 +4,6 @@ When developing applications, sometimes we cache computation results using hooks
4
4
 
5
5
  Modern.js supports caching server-side rendering (SSR) results, reducing the computational and rendering time during subsequent requests. This accelerates page load time and improves user experience. Additionally, caching lowers server load, conserves computational resources, and speeds up user access.
6
6
 
7
- :::tip
8
- Requires version x.43.0+
9
- :::
10
-
11
7
  ## Configuration
12
8
 
13
9
  Create a `server/cache.[t|j]s` file in your application and export the `cacheOption` configuration to enable SSR rendering cache:
@@ -32,10 +32,6 @@ import Logo from './logo.svg?react';
32
32
  export default () => <Logo />;
33
33
  ```
34
34
 
35
- :::tip
36
- Modern.js >= MAJOR_VERSION.48.3 version supports the above usage.
37
- :::
38
-
39
35
  Modern.js also supports the following usage, transforming SVG into a React component by named import `ReactComponent`:
40
36
 
41
37
  ```tsx title="src/component/Logo.tsx"
@@ -34,7 +34,7 @@ Modern.js uses [Rspack](https://rspack.rs/) to bundle your web applications.
34
34
 
35
35
  Modern.js uses [SWC](https://swc.rs/) as JavaScript transpiler to transform TypeScript or JSX into JavaScript code that can run in browsers and perform syntax downgrades.
36
36
 
37
- When using Rspack for building, `babel-loader` is not enabled by default. If you need to add [Babel](https://babeljs.io/) plugins, you can configure them through `tools.babel`, which will generate additional compilation overhead and slow down Rspack build speed to some extent.
37
+ When using Rspack for building, `babel-loader` is not enabled by default. If you need to add [Babel](https://babeljs.io/) plugins, you can configure them through [`babel plugin`](https://rsbuild.rs/plugins/list/plugin-babel#babel-plugin), which will generate additional compilation overhead and slow down Rspack build speed to some extent.
38
38
 
39
39
  ## Minimizer
40
40
 
@@ -0,0 +1 @@
1
+ ["overview", "config", "entry", "web-server", "tailwindcss", "other"]