@bleedingdev/modern-js-main-doc 3.5.0-ultramodern.97 → 3.5.0-ultramodern.99

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 (28) hide show
  1. package/docs/en/apis/app/hooks/config/mock.mdx +4 -1
  2. package/docs/en/configure/app/bff/effect.mdx +24 -7
  3. package/docs/en/configure/app/dev/mock-dir.mdx +35 -0
  4. package/docs/en/configure/app/server/rsc.mdx +1 -1
  5. package/docs/en/configure/app/source/react-compiler.mdx +72 -0
  6. package/docs/en/guides/advanced-features/international/api.mdx +41 -8
  7. package/docs/en/guides/basic-features/debug/mock.mdx +11 -0
  8. package/docs/en/guides/basic-features/deploy.mdx +6 -6
  9. package/docs/en/guides/basic-features/render/rsc.mdx +2 -2
  10. package/docs/en/guides/get-started/ai-coding-agents.mdx +19 -4
  11. package/docs/en/guides/get-started/tech-stack.mdx +1 -1
  12. package/docs/en/guides/get-started/ultramodern.mdx +4 -4
  13. package/docs/en/guides/topic-detail/module-federation/application.mdx +4 -4
  14. package/docs/en/guides/topic-detail/module-federation/usage.mdx +1 -1
  15. package/docs/zh/apis/app/hooks/config/mock.mdx +3 -1
  16. package/docs/zh/configure/app/bff/effect.mdx +22 -7
  17. package/docs/zh/configure/app/dev/mock-dir.mdx +33 -0
  18. package/docs/zh/configure/app/server/rsc.mdx +1 -1
  19. package/docs/zh/configure/app/source/react-compiler.mdx +72 -0
  20. package/docs/zh/guides/advanced-features/international/api.mdx +39 -8
  21. package/docs/zh/guides/basic-features/debug/mock.mdx +10 -0
  22. package/docs/zh/guides/basic-features/deploy.mdx +1 -1
  23. package/docs/zh/guides/basic-features/render/rsc.mdx +2 -2
  24. package/docs/zh/guides/get-started/ai-coding-agents.mdx +19 -4
  25. package/docs/zh/guides/get-started/ultramodern.mdx +4 -4
  26. package/docs/zh/guides/topic-detail/module-federation/application.mdx +4 -4
  27. package/docs/zh/guides/topic-detail/module-federation/usage.mdx +1 -1
  28. package/package.json +2 -2
@@ -4,4 +4,7 @@ sidebar_position: 5
4
4
  ---
5
5
  # mock/
6
6
 
7
- When there is a `config/mock/index.js` file in the project directory, Modern.js will automatically enable the Mock service during development.
7
+ When there is a `config/mock/index.ts` or `config/mock/index.js` file in the
8
+ project directory, Modern.js will automatically enable the Mock service during
9
+ development. Use [`dev.mockDir`](/configure/app/dev/mock-dir) to customize
10
+ this directory.
@@ -45,6 +45,23 @@ import EnableBFFCaution from "@site-docs-en/components/enable-bff-caution";
45
45
 
46
46
  `bff.effect` is only effective when `bff.runtimeFramework` is set to `'effect'`.
47
47
 
48
+ :::caution Install the Effect peers yourself
49
+ `effect` and `@effect/opentelemetry` are **optional exact peer dependencies** of
50
+ `@modern-js/plugin-bff`, not dependencies. The plugin no longer bundles a copy —
51
+ Effect 4 derives `Context` / `Service` keys per module instance, so a bundled copy
52
+ would give your app a second Effect identity. Before setting
53
+ `runtimeFramework: 'effect'` or importing `@modern-js/plugin-bff/effect`,
54
+ `/effect-server`, `/effect-edge` or `/effect-client`, install the exact cohort:
55
+
56
+ ```bash
57
+ pnpm add effect@4.0.0-beta.102 @effect/opentelemetry@4.0.0-beta.102
58
+ ```
59
+
60
+ The pin is exact because UltraModern ships Effect as one lockstep cohort. Apps
61
+ using only `runtimeFramework: 'hono'` or the `./data-platform` lane need neither
62
+ package.
63
+ :::
64
+
48
65
  Generated UltraModern workspaces use this runtime as the only generated HTTP API
49
66
  path. The API contract lives at `shared/api.ts`, the server runtime lives at
50
67
  `api/index.ts`, clients live under `src/api/*-client.ts`, and generated checks
@@ -202,17 +219,17 @@ generated apps use:
202
219
 
203
220
  ```yaml
204
221
  minimumReleaseAgeExclude:
205
- - 'effect@4.0.0-beta.97'
206
- - '@effect/opentelemetry@4.0.0-beta.97'
222
+ - 'effect@4.0.0-beta.102'
223
+ - '@effect/opentelemetry@4.0.0-beta.102'
207
224
 
208
225
  trustPolicyExclude:
209
- - 'effect@4.0.0-beta.97'
210
- - '@effect/opentelemetry@4.0.0-beta.97'
226
+ - 'effect@4.0.0-beta.102'
227
+ - '@effect/opentelemetry@4.0.0-beta.102'
211
228
 
212
229
  overrides:
213
- '@effect/opentelemetry': 4.0.0-beta.97
214
- '@effect/vitest': 4.0.0-beta.97
215
- effect: 4.0.0-beta.97
230
+ '@effect/opentelemetry': 4.0.0-beta.102
231
+ '@effect/vitest': 4.0.0-beta.102
232
+ effect: 4.0.0-beta.102
216
233
  ```
217
234
 
218
235
  Do not add a different direct `effect` version in an app package. A mismatched
@@ -0,0 +1,35 @@
1
+ ---
2
+ title: mockDir
3
+ ---
4
+
5
+ # dev.mockDir
6
+
7
+ - **Type:** `string`
8
+ - **Default:** `'./config/mock'`
9
+
10
+ Sets the directory containing the Mock API entry file. Relative paths are
11
+ resolved from the application directory, and absolute paths are also supported.
12
+ Modern.js loads `index.ts` or `index.js` from this directory during development.
13
+
14
+ For example, move the Mock API entry to `mocks/index.ts`:
15
+
16
+ ```js title="modern.config.ts"
17
+ import { defineConfig } from '@modern-js/app-tools';
18
+
19
+ export default defineConfig({
20
+ dev: {
21
+ mockDir: './mocks',
22
+ },
23
+ });
24
+ ```
25
+
26
+ This is also useful in a monorepo when multiple applications share one Mock
27
+ directory:
28
+
29
+ ```js title="modern.config.ts"
30
+ export default defineConfig({
31
+ dev: {
32
+ mockDir: '../../shared/mocks',
33
+ },
34
+ });
35
+ ```
@@ -22,7 +22,7 @@ export default defineConfig({
22
22
  :::tip Prerequisites
23
23
  Before enabling RSC, ensure:
24
24
  1. React and React DOM are upgraded to version 19 (recommended 19.2.4 or above)
25
- 2. Install the `react-server-dom-rspack@0.0.1-beta.1` dependency
25
+ 2. Install the `react-server-dom-rspack@0.0.2` dependency
26
26
 
27
27
  :::
28
28
 
@@ -0,0 +1,72 @@
1
+ ---
2
+ title: reactCompiler
3
+ ---
4
+
5
+ # source.reactCompiler
6
+
7
+ - **Type:** `boolean | ReactCompilerOptions`
8
+ - **Default:** `undefined` (disabled)
9
+
10
+ Whether to enable [React Compiler](https://react.dev/learn/react-compiler). React Compiler is a build-time tool that optimizes re-rendering performance of React applications through automatic memoization.
11
+
12
+ Modern.js implements this capability based on the Rust-based React Compiler built into Rspack's `builtin:swc-loader` (equivalent to setting SWC's `jsc.transform.reactCompiler`), reusing Rspack's built-in SWC transform chain without introducing Babel.
13
+
14
+ :::tip
15
+ This option is disabled by default. It must be enabled explicitly for any React version, including React 19.
16
+ :::
17
+
18
+ ## Example
19
+
20
+ ### Enable React Compiler (React 19)
21
+
22
+ ```ts title="modern.config.ts"
23
+ import { defineConfig } from '@modern-js/app-tools';
24
+
25
+ export default defineConfig({
26
+ source: {
27
+ reactCompiler: true,
28
+ },
29
+ });
30
+ ```
31
+
32
+ ### Using with React 18
33
+
34
+ The compiled output targets React 19 by default. To use it in React 18 projects, you need to:
35
+
36
+ 1. Install [react-compiler-runtime](https://www.npmjs.com/package/react-compiler-runtime) as a **runtime dependency** (the compiled output references it at runtime):
37
+
38
+ ```bash
39
+ npm add react-compiler-runtime
40
+ ```
41
+
42
+ 2. Specify the React version via `target`:
43
+
44
+ ```ts title="modern.config.ts"
45
+ import { defineConfig } from '@modern-js/app-tools';
46
+
47
+ export default defineConfig({
48
+ source: {
49
+ reactCompiler: {
50
+ target: '18',
51
+ },
52
+ },
53
+ });
54
+ ```
55
+
56
+ ### Customize compilation behavior
57
+
58
+ When passing an object, the options are the same as Rspack's `jsc.transform.reactCompiler`. For example, use `compilationMode: 'annotation'` to only compile functions annotated with the `"use memo"` directive:
59
+
60
+ ```ts title="modern.config.ts"
61
+ import { defineConfig } from '@modern-js/app-tools';
62
+
63
+ export default defineConfig({
64
+ source: {
65
+ reactCompiler: {
66
+ compilationMode: 'annotation',
67
+ },
68
+ },
69
+ });
70
+ ```
71
+
72
+ For the complete list of options, see [Rsbuild - reactCompiler](https://rsbuild.rs/plugins/list/plugin-react#reactcompiler) and the [React Compiler configuration docs](https://react.dev/reference/react-compiler/configuration).
@@ -145,19 +145,52 @@ const myPlugin = (): RuntimePlugin => ({
145
145
 
146
146
  The i18next instance type used by the plugin. It is a subset of the i18next `i18n` type and only lists fields actually used by the plugin:
147
147
 
148
+ :::warning BREAKING (UltraModern)
149
+ `I18nInstance` no longer declares a top-level `[key: string]: unknown` index
150
+ signature: TypeScript never grants an interface an implicit index signature, so
151
+ that member made the documented `runtime: { i18n: { i18nInstance: i18next } }`
152
+ usage fail to typecheck. Reading a property that is not declared below is now a
153
+ type error (TS2339) — cast to the concrete instance type instead. `t` is now a
154
+ REQUIRED member, so object literals that produce an `I18nInstance` must supply
155
+ one.
156
+ :::
157
+
148
158
  ```ts
159
+ type TranslateFn = (
160
+ key: string | string[],
161
+ options?: Record<string, unknown>,
162
+ ) => string;
163
+
149
164
  interface I18nInstance {
150
165
  language: string;
151
- isInitialized: boolean;
152
- init: (options?: I18nInitOptions) => void | Promise<void>;
153
- changeLanguage: (lang: string) => void | Promise<void>;
154
- use: (plugin: any) => void;
155
- createInstance: (options?: I18nInitOptions) => I18nInstance;
166
+ isInitialized?: boolean;
167
+ init(options?: any, callback?: any): Promise<any>;
168
+ changeLanguage?(lng?: string, callback?: any): Promise<any>;
169
+ setLang?: (lang: string) => void | Promise<void>;
170
+ use(plugin: any): unknown;
171
+ t: TranslateFn;
172
+ exists?: (key: string | string[], options?: Record<string, unknown>) => boolean;
173
+ getFixedT?: (
174
+ lng: string | readonly string[] | null,
175
+ ns?: string | readonly string[] | null,
176
+ keyPrefix?: string,
177
+ ) => TranslateFn;
178
+ hasLoadedNamespace?: (
179
+ ns: string | readonly string[],
180
+ options?: Record<string, unknown>,
181
+ ) => boolean;
182
+ dir?: (lng?: string) => string;
183
+ languages?: readonly string[];
184
+ resolvedLanguage?: string;
185
+ createInstance?(options?: any, callback?: any): I18nInstance;
186
+ cloneInstance?(options?: any, callback?: any): I18nInstance;
156
187
  options?: {
157
- backend?: BackendOptions;
158
- supportedLngs?: string[];
159
- [key: string]: any;
188
+ detection?: any;
189
+ backend?: any;
190
+ ns?: any;
191
+ defaultNS?: any;
160
192
  };
193
+ // ...see src/runtime/i18n/instance.ts for the full member list.
161
194
  }
162
195
  ```
163
196
 
@@ -20,6 +20,17 @@ By convention, when there is an `index.ts` in the `config/mock/` directory, mock
20
20
  └── modern.config.ts
21
21
  ```
22
22
 
23
+ You can use [`dev.mockDir`](/configure/app/dev/mock-dir) to place the
24
+ Mock entry in another directory:
25
+
26
+ ```js title="modern.config.ts"
27
+ export default {
28
+ dev: {
29
+ mockDir: './mocks',
30
+ },
31
+ };
32
+ ```
33
+
23
34
  ## Writing Mock Files
24
35
 
25
36
  The `config/mock/index.ts` file only needs to export an object containing all Mock APIs. The properties of the object are composed of the request configuration `method` and `url`, and the corresponding property values can be `Object`, `Array`, or `Function`:
@@ -112,7 +112,7 @@ Add the following content to `netlify.toml`:
112
112
  ```
113
113
 
114
114
  :::info
115
- You can refer to the [deployment project example](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/modern-js-deploy-csr).
115
+ You can refer to the [deployment project example](https://github.com/web-infra-dev/modern.js/tree/main/examples/modern-js-deploy-csr).
116
116
 
117
117
  :::
118
118
 
@@ -137,7 +137,7 @@ Full-stack projects refer to projects that use Custom Web Server, SSR or BFF. Th
137
137
  :::info
138
138
 
139
139
  1. Currently, Modern.js does not support deployment on Netlify Edge Functions. We will support it in future versions.
140
- 2. You can refer to the [deployment project example](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/modern-js-deploy-ssr).
140
+ 2. You can refer to the [deployment project example](https://github.com/web-infra-dev/modern.js/tree/main/examples/modern-js-deploy-ssr).
141
141
 
142
142
  :::
143
143
 
@@ -223,7 +223,7 @@ Commit your project to git, select Framework Preset as `Other` on the Vercel pla
223
223
  <img src="https://sf16-sg.tiktokcdn.com/obj/eden-sg/lmeh7nuptpfnuhd/vercel-framework-preset.png" />
224
224
 
225
225
  :::info
226
- You can refer to the [deployment project examples](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/modern-js-deploy-csr).
226
+ You can refer to the [deployment project examples](https://github.com/web-infra-dev/modern.js/tree/main/examples/modern-js-deploy-csr).
227
227
 
228
228
  :::
229
229
 
@@ -237,7 +237,7 @@ In addition to configuring `vercel.json` in the same way as a [pure front-end pr
237
237
  2. The Node.js version for function execution is determined by the project configuration on the Vercel platform.
238
238
 
239
239
  :::info
240
- You can refer to the [deployment project examples](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/modern-js-deploy-ssr).
240
+ You can refer to the [deployment project examples](https://github.com/web-infra-dev/modern.js/tree/main/examples/modern-js-deploy-ssr).
241
241
 
242
242
  :::
243
243
 
@@ -335,10 +335,10 @@ For branch deployment, follow these steps:
335
335
  :::info
336
336
 
337
337
  1. Running `MODERNJS_DEPLOY=ghPages modern deploy` will build the production output for GitHub in the .output directory.
338
- 2. You can refer to the [project](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/modern-js-deploy-csr)
338
+ 2. You can refer to the [project](https://github.com/web-infra-dev/modern.js/tree/main/examples/modern-js-deploy-csr)
339
339
  :::
340
340
 
341
- For GitHub Actions deployment, select Settings > Pages > Source > GitHub Actions, and add a workflow file to the project. You can refer to the [example](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/modern-js-deploy-csr).
341
+ For GitHub Actions deployment, select Settings > Pages > Source > GitHub Actions, and add a workflow file to the project. You can refer to the [example](https://github.com/web-infra-dev/modern.js/tree/main/examples/modern-js-deploy-csr).
342
342
 
343
343
  ## Using Self-Built Node.js Server
344
344
 
@@ -23,10 +23,10 @@ Before starting, we recommend reading React's official [Server Components docume
23
23
 
24
24
  1. **Ensure React and React DOM are upgraded to version 19** (recommended version 19.2.4 or above)
25
25
 
26
- 2. **Install the `react-server-dom-rspack@0.0.1-beta.1` dependency**
26
+ 2. **Install the `react-server-dom-rspack@0.0.2` dependency**
27
27
 
28
28
  ```bash
29
- npm install react-server-dom-rspack@0.0.1-beta.1
29
+ npm install react-server-dom-rspack@0.0.2
30
30
  ```
31
31
 
32
32
  :::warning Notes
@@ -5,16 +5,31 @@ sidebar_position: 6
5
5
 
6
6
  # Modern.js For AI
7
7
 
8
- Modern.js provides a toolkit for AI agents that helps developers use AI to efficiently complete feature development, dependency upgrades, and version migration for Modern.js applications.
8
+ Modern.js provides a toolkit for AI agents that makes your project agent-ready out of the box, helping you use AI to develop, upgrade, and migrate Modern.js applications more accurately and efficiently.
9
+
10
+ ## Bundled docs
11
+
12
+ Modern.js ships the English docs that match your installed version together with `@modern-js/app-tools`. After you install or upgrade, they live at `node_modules/@modern-js/app-tools/docs/`, available offline with no extra setup.
13
+
14
+ AI agents use them to get APIs, config, and conventions that exactly match your framework version, rather than relying on potentially outdated training data.
15
+
16
+ ## AGENTS.md
17
+
18
+ `AGENTS.md` gives AI coding agents project-level guidance — telling them to read the bundled docs before making changes and to follow Modern.js conventions. A `CLAUDE.md` is generated alongside it, reusing the same guidance for Claude Code via the `@AGENTS.md` import.
19
+
20
+ - **New projects**: `npx @modern-js/create` generates both files by default; pass `--no-agents-md` to skip them.
21
+ - **Existing projects**: run `npx @modern-js/create agents-md` at the project root to create or update them. Re-run it any time; your own additions are preserved.
22
+
23
+ Modern.js only maintains the content inside the `<!-- BEGIN:modernjs-agent-rules -->` markers in `AGENTS.md`; anything you write outside them is left untouched.
9
24
 
10
25
  ## llms.txt
11
26
 
12
- Modern.js docs follow the [llms.txt specification](https://llmstxt.org/), auto-generated by [`@rspress/plugin-llms`](https://rspress.rs/plugin/official-plugins/llms), accessible via `/llms.txt` or `/llms-full.txt`:
27
+ llms.txt is an online documentation index following the [llms.txt specification](https://llmstxt.org/), auto-generated by [`@rspress/plugin-llms`](https://rspress.rs/plugin/official-plugins/llms) for AI tools to retrieve the full docs online:
13
28
 
14
29
  - Index: [`https://modernjs.dev/llms.txt`](https://modernjs.dev/llms.txt)
15
- - Full text: `https://modernjs.dev/llms-full.txt` (large — fetch on demand)
30
+ - Full text: [`https://modernjs.dev/llms-full.txt`](https://modernjs.dev/llms-full.txt) (large — fetch on demand)
16
31
 
17
- Most "what is this API / config" questions can be answered from llms.txt. Just let your agent retrieve it on demand; no need to copy docs into your project.
32
+ Use it when you need content beyond the bundled docs just let your agent retrieve it on demand, no need to copy docs into your project. Typical cases: looking up another framework version, a section not included in the bundle, or getting Modern.js information outside of a project (for example before a project exists, or when researching on its own).
18
33
 
19
34
  ## Skills
20
35
 
@@ -10,7 +10,7 @@ In this document, you can learn about the main technology stack involved in the
10
10
 
11
11
  ## UI Library
12
12
 
13
- Modern.js uses [React 18](https://react.dev/) to build user interfaces and is also compatible with React 17.
13
+ Modern.js uses [React 19](https://react.dev/) to build user interfaces and is also compatible with React 18.
14
14
 
15
15
  Rsbuild supports building Vue applications. If you need to use Vue, you can refer to ["Rsbuild - Vue"](https://v2.rsbuild.rs/guide/framework/vue).
16
16
 
@@ -143,11 +143,11 @@ migration work: move code to `shared/api.ts`, `api/index.ts`, and
143
143
  and `src/effect`.
144
144
 
145
145
  Generated strict Effect workspaces pin the compatible Effect cohort with pnpm
146
- overrides: `effect@4.0.0-beta.97`, `@effect/opentelemetry@4.0.0-beta.97`,
147
- and `@effect/vitest@4.0.0-beta.97`. Do not add app-local direct Effect
146
+ overrides: `effect@4.0.0-beta.102`, `@effect/opentelemetry@4.0.0-beta.102`,
147
+ and `@effect/vitest@4.0.0-beta.102`. Do not add app-local direct Effect
148
148
  versions that disagree with those overrides. They also carry generated pnpm
149
- policy exclusions for `effect@4.0.0-beta.97` and
150
- `@effect/opentelemetry@4.0.0-beta.97` so the framework-selected Effect beta
149
+ policy exclusions for `effect@4.0.0-beta.102` and
150
+ `@effect/opentelemetry@4.0.0-beta.102` so the framework-selected Effect beta
151
151
  cohort is not blocked by the 24-hour age gate or trusted-publisher to
152
152
  provenance metadata transition.
153
153
 
@@ -62,7 +62,7 @@ export default createModuleFederationConfig({
62
62
  ```
63
63
 
64
64
  :::info
65
- [`createBridgeComponent`](https://module-federation.io/practice/bridge/react-bridge/export-app.html#createbridgecomponent-api-reference) is used to export application-level modules. Modern.js related APIs can be found at [createRoot](/apis/app/runtime/core/create-root) and [render](/apis/app/runtime/core/render).
65
+ [`createBridgeComponent`](https://module-federation.io/guide/bridge/overview#core-apis) is used to export application-level modules. Modern.js related APIs can be found at [createRoot](/apis/app/runtime/core/create-root) and [render](/apis/app/runtime/core/render).
66
66
  :::
67
67
 
68
68
  ## Using Modules in Consumer
@@ -98,7 +98,7 @@ export default RemoteApp;
98
98
  ```
99
99
 
100
100
  :::info
101
- [`createRemoteAppComponent`](https://module-federation.io/zh/practice/bridge/react-bridge/load-app.html#%E4%BB%80%E4%B9%88%E6%98%AF-createremoteappcomponent) is used to load application-level modules.
101
+ [`createRemoteAppComponent`](https://module-federation.io/guide/bridge/overview#core-apis) is used to load application-level modules.
102
102
  :::
103
103
 
104
104
  ## Start the Application
@@ -109,8 +109,8 @@ After startup, when the consumer application accesses the `/remote` route, it wi
109
109
 
110
110
  You can create new route files in the producer application and add route navigation in the code. These functionalities will also work as expected.
111
111
 
112
- You can refer to the example here: [Modern.js & Module Federation Application-Level Modules](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/module-federation/app-export).
112
+ You can refer to the example here: [Modern.js & Module Federation Application-Level Modules](https://github.com/web-infra-dev/modern.js/tree/main/examples/module-federation/app-export).
113
113
 
114
114
  ## Related Documentation
115
115
 
116
- - [Module Federation Bridge](https://module-federation.io/zh/practice/bridge/index.html)
116
+ - [Module Federation Bridge](https://module-federation.io/guide/bridge/overview)
@@ -195,7 +195,7 @@ Now, in the producer, run `modern build && MODERN_MF_AUTO_CORS=true modern serv
195
195
  When using the `modern serve` command, you need to set the `MODERN_MF_AUTO_CORS=true` environment variable when starting the producer project to automatically handle CORS issues and ensure that consumers can properly access the producer's remote module resources.
196
196
  :::
197
197
 
198
- You can refer to this example: [Modern.js & Module Federation Basic Example](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/module-federation/base).
198
+ You can refer to this example: [Modern.js & Module Federation Basic Example](https://github.com/web-infra-dev/modern.js/tree/main/examples/module-federation/base).
199
199
 
200
200
  ## Related Documentation
201
201
 
@@ -4,4 +4,6 @@ sidebar_position: 5
4
4
  ---
5
5
  # mock/
6
6
 
7
- 当项目目录下存在 `config/mock/index.js` 时,Modern.js 在开发环节将自动开启 Mock 服务。
7
+ 当项目目录下存在 `config/mock/index.ts` 或 `config/mock/index.js` 时,Modern.js
8
+ 会在开发环节自动开启 Mock 服务。可以通过
9
+ [`dev.mockDir`](/configure/app/dev/mock-dir) 自定义该目录。
@@ -45,6 +45,21 @@ import EnableBFFCaution from "@site-docs/components/enable-bff-caution";
45
45
 
46
46
  仅当 `bff.runtimeFramework` 设置为 `'effect'` 时,`bff.effect` 才会生效。
47
47
 
48
+ :::caution 需要自行安装 Effect peer 依赖
49
+ `effect` 与 `@effect/opentelemetry` 是 `@modern-js/plugin-bff` 的**可选精确 peer
50
+ 依赖**,而不是直接依赖。插件不再自带副本——Effect 4 的 `Context` / `Service` 键按模块
51
+ 实例生成,自带副本会让应用出现第二份 Effect 身份。在设置 `runtimeFramework: 'effect'`
52
+ 或引入 `@modern-js/plugin-bff/effect`、`/effect-server`、`/effect-edge`、
53
+ `/effect-client` 之前,请安装精确版本的依赖组:
54
+
55
+ ```bash
56
+ pnpm add effect@4.0.0-beta.102 @effect/opentelemetry@4.0.0-beta.102
57
+ ```
58
+
59
+ 采用精确版本是因为 UltraModern 以锁步依赖组的方式发布 Effect。只使用
60
+ `runtimeFramework: 'hono'` 或 `./data-platform` 通道的应用无需安装这两个包。
61
+ :::
62
+
48
63
  生成的 UltraModern workspace 只把这个运行时作为生成 HTTP API 路径。API 契约固定在
49
64
  `shared/api.ts`,服务端运行时固定在 `api/index.ts`,客户端固定在
50
65
  `src/api/*-client.ts`。生成检查会拒绝 `api/effect`、`api/lambda`、
@@ -199,17 +214,17 @@ Effect 版本组。当前 UltraModern 版本组使用:
199
214
 
200
215
  ```yaml
201
216
  minimumReleaseAgeExclude:
202
- - 'effect@4.0.0-beta.97'
203
- - '@effect/opentelemetry@4.0.0-beta.97'
217
+ - 'effect@4.0.0-beta.102'
218
+ - '@effect/opentelemetry@4.0.0-beta.102'
204
219
 
205
220
  trustPolicyExclude:
206
- - 'effect@4.0.0-beta.97'
207
- - '@effect/opentelemetry@4.0.0-beta.97'
221
+ - 'effect@4.0.0-beta.102'
222
+ - '@effect/opentelemetry@4.0.0-beta.102'
208
223
 
209
224
  overrides:
210
- '@effect/opentelemetry': 4.0.0-beta.97
211
- '@effect/vitest': 4.0.0-beta.97
212
- effect: 4.0.0-beta.97
225
+ '@effect/opentelemetry': 4.0.0-beta.102
226
+ '@effect/vitest': 4.0.0-beta.102
227
+ effect: 4.0.0-beta.102
213
228
  ```
214
229
 
215
230
  不要在应用包里添加不同版本的直接 `effect` 依赖。Effect beta 不一致时,Layer 或 HTTP
@@ -0,0 +1,33 @@
1
+ ---
2
+ title: mockDir
3
+ ---
4
+
5
+ # dev.mockDir
6
+
7
+ - **类型:** `string`
8
+ - **默认值:** `'./config/mock'`
9
+
10
+ 设置 Mock API 入口文件所在的目录。相对路径基于应用目录解析,同时也支持绝对路径。
11
+ 开发环境下,Modern.js 会加载该目录中的 `index.ts` 或 `index.js`。
12
+
13
+ 例如,将 Mock API 入口移动到 `mocks/index.ts`:
14
+
15
+ ```js title="modern.config.ts"
16
+ import { defineConfig } from '@modern-js/app-tools';
17
+
18
+ export default defineConfig({
19
+ dev: {
20
+ mockDir: './mocks',
21
+ },
22
+ });
23
+ ```
24
+
25
+ 在 Monorepo 中,也可以让多个应用指向一个共享的 Mock 目录:
26
+
27
+ ```js title="modern.config.ts"
28
+ export default defineConfig({
29
+ dev: {
30
+ mockDir: '../../shared/mocks',
31
+ },
32
+ });
33
+ ```
@@ -22,7 +22,7 @@ export default defineConfig({
22
22
  :::tip 前置条件
23
23
  在启用 RSC 之前,请确保:
24
24
  1. React 和 React DOM 已升级到 19 版本(建议 19.2.4 以上版本)
25
- 2. 已安装 `react-server-dom-rspack@0.0.1-beta.1` 依赖
25
+ 2. 已安装 `react-server-dom-rspack@0.0.2` 依赖
26
26
 
27
27
  :::
28
28
 
@@ -0,0 +1,72 @@
1
+ ---
2
+ title: reactCompiler
3
+ ---
4
+
5
+ # source.reactCompiler
6
+
7
+ - **类型:** `boolean | ReactCompilerOptions`
8
+ - **默认值:** `undefined`(不开启)
9
+
10
+ 是否启用 [React Compiler](https://zh-hans.react.dev/learn/react-compiler)。React Compiler 是一个构建期工具,通过自动记忆化(memoization)优化 React 应用的重渲染性能。
11
+
12
+ Modern.js 基于 Rspack `builtin:swc-loader` 内置的 Rust 版 React Compiler 实现该能力(等价于设置 SWC 的 `jsc.transform.reactCompiler`),复用 Rspack 内置的 SWC 转换链,无需额外引入 Babel。
13
+
14
+ :::tip
15
+ 该配置默认关闭,任何 React 版本下都需要显式开启,包括 React 19。
16
+ :::
17
+
18
+ ## 示例
19
+
20
+ ### 开启 React Compiler(React 19)
21
+
22
+ ```ts title="modern.config.ts"
23
+ import { defineConfig } from '@modern-js/app-tools';
24
+
25
+ export default defineConfig({
26
+ source: {
27
+ reactCompiler: true,
28
+ },
29
+ });
30
+ ```
31
+
32
+ ### 在 React 18 中使用
33
+
34
+ React Compiler 编译产物默认面向 React 19。在 React 18 项目中使用时,需要:
35
+
36
+ 1. 将 [react-compiler-runtime](https://www.npmjs.com/package/react-compiler-runtime) 安装为**运行时依赖**(编译产物会在运行时引用它):
37
+
38
+ ```bash
39
+ npm add react-compiler-runtime
40
+ ```
41
+
42
+ 2. 通过 `target` 指定 React 版本:
43
+
44
+ ```ts title="modern.config.ts"
45
+ import { defineConfig } from '@modern-js/app-tools';
46
+
47
+ export default defineConfig({
48
+ source: {
49
+ reactCompiler: {
50
+ target: '18',
51
+ },
52
+ },
53
+ });
54
+ ```
55
+
56
+ ### 自定义编译行为
57
+
58
+ 传入对象时,选项与 Rspack `jsc.transform.reactCompiler` 一致,例如通过 `compilationMode: 'annotation'` 仅编译带有 `"use memo"` 指令的函数:
59
+
60
+ ```ts title="modern.config.ts"
61
+ import { defineConfig } from '@modern-js/app-tools';
62
+
63
+ export default defineConfig({
64
+ source: {
65
+ reactCompiler: {
66
+ compilationMode: 'annotation',
67
+ },
68
+ },
69
+ });
70
+ ```
71
+
72
+ 完整选项请参考 [Rsbuild - reactCompiler](https://rsbuild.rs/plugins/list/plugin-react#reactcompiler) 与 [React Compiler 配置文档](https://zh-hans.react.dev/reference/react-compiler/configuration)。
@@ -144,19 +144,50 @@ const myPlugin = (): RuntimePlugin => ({
144
144
 
145
145
  插件使用的 i18next 实例类型(i18next `i18n` 类型的子集,仅列出插件实际使用的字段):
146
146
 
147
+ :::warning 破坏性变更(UltraModern)
148
+ `I18nInstance` 不再声明顶层的 `[key: string]: unknown` 索引签名:TypeScript 永远不会
149
+ 为 interface 自动添加隐式索引签名,该成员会让文档中的
150
+ `runtime: { i18n: { i18nInstance: i18next } }` 用法无法通过类型检查。读取下方未声明的
151
+ 属性现在会报类型错误(TS2339),请改为断言到具体的实例类型。`t` 现在是**必需**成员,
152
+ 因此以对象字面量构造 `I18nInstance` 时必须提供 `t`。
153
+ :::
154
+
147
155
  ```ts
156
+ type TranslateFn = (
157
+ key: string | string[],
158
+ options?: Record<string, unknown>,
159
+ ) => string;
160
+
148
161
  interface I18nInstance {
149
162
  language: string;
150
- isInitialized: boolean;
151
- init: (options?: I18nInitOptions) => void | Promise<void>;
152
- changeLanguage: (lang: string) => void | Promise<void>;
153
- use: (plugin: any) => void;
154
- createInstance: (options?: I18nInitOptions) => I18nInstance;
163
+ isInitialized?: boolean;
164
+ init(options?: any, callback?: any): Promise<any>;
165
+ changeLanguage?(lng?: string, callback?: any): Promise<any>;
166
+ setLang?: (lang: string) => void | Promise<void>;
167
+ use(plugin: any): unknown;
168
+ t: TranslateFn;
169
+ exists?: (key: string | string[], options?: Record<string, unknown>) => boolean;
170
+ getFixedT?: (
171
+ lng: string | readonly string[] | null,
172
+ ns?: string | readonly string[] | null,
173
+ keyPrefix?: string,
174
+ ) => TranslateFn;
175
+ hasLoadedNamespace?: (
176
+ ns: string | readonly string[],
177
+ options?: Record<string, unknown>,
178
+ ) => boolean;
179
+ dir?: (lng?: string) => string;
180
+ languages?: readonly string[];
181
+ resolvedLanguage?: string;
182
+ createInstance?(options?: any, callback?: any): I18nInstance;
183
+ cloneInstance?(options?: any, callback?: any): I18nInstance;
155
184
  options?: {
156
- backend?: BackendOptions;
157
- supportedLngs?: string[];
158
- [key: string]: any;
185
+ detection?: any;
186
+ backend?: any;
187
+ ns?: any;
188
+ defaultNS?: any;
159
189
  };
190
+ // ...完整成员列表见 src/runtime/i18n/instance.ts。
160
191
  }
161
192
  ```
162
193
 
@@ -20,6 +20,16 @@ Modern.js 提供了快速生成 Mock 数据的功能,能够让前端独立自
20
20
  └── modern.config.ts
21
21
  ```
22
22
 
23
+ 你可以通过 [`dev.mockDir`](/configure/app/dev/mock-dir) 将 Mock 入口放到其他目录:
24
+
25
+ ```js title="modern.config.ts"
26
+ export default {
27
+ dev: {
28
+ mockDir: './mocks',
29
+ },
30
+ };
31
+ ```
32
+
23
33
  ## 编写 Mock 文件
24
34
 
25
35
  `config/mock/index.ts` 文件只需要导出一个包含所有 Mock API 的对象,对象的属性由请求配置 `method` 和 `url` 组成,对应的属性值可以为 `Object`、`Array`、`Function`:
@@ -317,7 +317,7 @@ Github Pages 支持两种部署方式,通过分支部署或通过 Github Actio
317
317
  :::info
318
318
 
319
319
  1. 执行 `MODERNJS_DEPLOY=ghPages modern deploy`,UltraModern.js 会把可用于 github 部署的产物构建到 `.output` 目录。
320
- 2. 可以参考项目[示例](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/modern-js-deploy-csr)。
320
+ 2. 可以参考仓库内的[示例](https://github.com/web-infra-dev/modern.js/tree/main/examples/modern-js-deploy-csr)。
321
321
 
322
322
  :::
323
323
 
@@ -23,10 +23,10 @@ React Server Components (RSC) 是一种新的组件类型,允许在服务端
23
23
 
24
24
  1. **确保 React 和 React DOM 升级到 19 版本**(建议 19.2.4 以上版本)
25
25
 
26
- 2. **安装 `react-server-dom-rspack@0.0.1-beta.1` 依赖**
26
+ 2. **安装 `react-server-dom-rspack@0.0.2` 依赖**
27
27
 
28
28
  ```bash
29
- npm install react-server-dom-rspack@0.0.1-beta.1
29
+ npm install react-server-dom-rspack@0.0.2
30
30
  ```
31
31
 
32
32
  :::warning 注意事项
@@ -5,16 +5,31 @@ sidebar_position: 6
5
5
 
6
6
  # Modern.js For AI
7
7
 
8
- Modern.js 为 AI Agent 提供了一套工具套件,帮助开发者利用 AI 高效完成 Modern.js 应用的功能开发、依赖升级与版本迁移工作。
8
+ Modern.js 为 AI Agent 提供了一套工具套件,让项目开箱即为 agent-ready,帮助你更准确、高效地用 AI 完成 Modern.js 应用的开发、升级与迁移。
9
+
10
+ ## 随包文档
11
+
12
+ Modern.js 把与你安装版本一致的英文文档随 `@modern-js/app-tools` 一起分发。安装或升级后,文档即位于 `node_modules/@modern-js/app-tools/docs/`,离线可用、无需额外配置。
13
+
14
+ AI Agent 由此获取与当前框架版本严格匹配的 API、配置与约定,而不是依赖可能过时的训练数据。
15
+
16
+ ## AGENTS.md
17
+
18
+ `AGENTS.md` 是给 AI 编码助手的项目指引,告诉它在动手前先阅读随包文档、并遵循 Modern.js 的约定;同时会生成 `CLAUDE.md`,通过 `@AGENTS.md` 让 Claude Code 复用同一份指引。
19
+
20
+ - **新建项目**:`npx @modern-js/create` 默认生成这两个文件,加 `--no-agents-md` 可跳过。
21
+ - **已有项目**:在项目根运行 `npx @modern-js/create agents-md` 生成或更新,可随时重复运行,你添加的自定义内容会被保留。
22
+
23
+ Modern.js 只维护 `AGENTS.md` 中 `<!-- BEGIN:modernjs-agent-rules -->` 标记内的内容,标记之外你写的内容不会被改动。
9
24
 
10
25
  ## llms.txt
11
26
 
12
- Modern.js 文档遵循 [llms.txt 规范](https://llmstxt.org/),由 [`@rspress/plugin-llms`](https://rspress.rs/plugin/official-plugins/llms) 自动生成,可通过 `/llms.txt` 或 `/llms-full.txt` 供 AI 工具检索:
27
+ llms.txt 是遵循 [llms.txt 规范](https://llmstxt.org/) 的在线文档索引,由 [`@rspress/plugin-llms`](https://rspress.rs/plugin/official-plugins/llms) 自动生成,供 AI 工具在线检索完整文档:
13
28
 
14
29
  - 索引:[`https://modernjs.dev/llms.txt`](https://modernjs.dev/llms.txt)
15
- - 全文:`https://modernjs.dev/llms-full.txt`(体积较大,按需取片段)
30
+ - 全文:[`https://modernjs.dev/llms-full.txt`](https://modernjs.dev/llms-full.txt)(体积较大,按需取片段)
16
31
 
17
- 大部分「这个 API / 配置是什么」类问题,靠 llms.txt 即可解决。让你的 Agent 按需检索它即可,不必把文档复制进项目。
32
+ 当需要查阅随包文档之外的内容时,让 Agent 在线检索它即可,不必把文档复制进项目。典型场景包括:查阅其他框架版本、随包未包含的章节,或在 Modern.js 项目之外获取信息(例如尚未创建项目、或独立查阅资料时)。
18
33
 
19
34
  ## Skills
20
35
 
@@ -128,10 +128,10 @@ pnpm overrides/trust policy 和 pnpm lockfile。剩余失败就是源码迁移
128
128
  `api/lambda`、`shared/effect` 和 `src/effect`。
129
129
 
130
130
  严格 Effect 生成 workspace 会通过 pnpm overrides 固定兼容版本组:
131
- `effect@4.0.0-beta.97`、`@effect/opentelemetry@4.0.0-beta.97` 和
132
- `@effect/vitest@4.0.0-beta.97`。不要添加与这些 overrides 冲突的 app 本地直接
133
- Effect 版本。生成的 pnpm policy 还会为 `effect@4.0.0-beta.97` 和
134
- `@effect/opentelemetry@4.0.0-beta.97` 添加例外,避免框架选定的 Effect beta
131
+ `effect@4.0.0-beta.102`、`@effect/opentelemetry@4.0.0-beta.102` 和
132
+ `@effect/vitest@4.0.0-beta.102`。不要添加与这些 overrides 冲突的 app 本地直接
133
+ Effect 版本。生成的 pnpm policy 还会为 `effect@4.0.0-beta.102` 和
134
+ `@effect/opentelemetry@4.0.0-beta.102` 添加例外,避免框架选定的 Effect beta
135
135
  版本组被 24 小时成熟期检查,或从 trusted-publisher metadata 迁移到 provenance
136
136
  attestation 时被 no-downgrade 检查误拦截。
137
137
 
@@ -63,7 +63,7 @@ export default createModuleFederationConfig({
63
63
  ```
64
64
 
65
65
  :::info
66
- [`createBridgeComponent`](https://module-federation.io/zh/practice/bridge/react-bridge/export-app.html#createbridgecomponent-api-%E5%8F%82%E8%80%83) 用于导出应用级别模块,Modern.js 相关 API 可以查看 [createRoot](/apis/app/runtime/core/create-root)、[render](/apis/app/runtime/core/render)。
66
+ [`createBridgeComponent`](https://module-federation.io/zh/guide/bridge/overview.html#%E6%A0%B8%E5%BF%83-api) 用于导出应用级别模块,Modern.js 相关 API 可以查看 [createRoot](/apis/app/runtime/core/create-root)、[render](/apis/app/runtime/core/render)。
67
67
  :::
68
68
 
69
69
  ## 消费者使用模块
@@ -99,7 +99,7 @@ export default RemoteApp;
99
99
  ```
100
100
 
101
101
  :::info
102
- [`createRemoteAppComponent`](https://module-federation.io/zh/practice/bridge/react-bridge/load-app.html#%E4%BB%80%E4%B9%88%E6%98%AF-createremoteappcomponent) 用于加载应用级别模块。
102
+ [`createRemoteAppComponent`](https://module-federation.io/zh/guide/bridge/overview.html#%E6%A0%B8%E5%BF%83-api) 用于加载应用级别模块。
103
103
  :::
104
104
 
105
105
  ## 启动应用
@@ -110,8 +110,8 @@ export default RemoteApp;
110
110
 
111
111
  你可以在生产者应用中,创建新的路由文件,并在代码中添加路由导航,可以发现这些功能也能够正常运行。
112
112
 
113
- 上述用例可以参考:[Modern.js & Module Federation 应用级别模块](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/module-federation/app-export)。
113
+ 上述用例可以参考:[Modern.js & Module Federation 应用级别模块](https://github.com/web-infra-dev/modern.js/tree/main/examples/module-federation/app-export)。
114
114
 
115
115
  ## 相关文档
116
116
 
117
- - [Module Federation Bridge](https://module-federation.io/zh/practice/bridge/index.html)
117
+ - [Module Federation Bridge](https://module-federation.io/zh/guide/bridge/overview)
@@ -193,7 +193,7 @@ export default defineConfig({
193
193
  在使用 `modern serve` 命令时,需要在启动生产者项目时携带 `MODERN_MF_AUTO_CORS=true` 环境变量,以自动处理跨域问题,确保消费者可以正常访问生产者的远程模块资源。
194
194
  :::
195
195
 
196
- 上述用例可以参考:[Modern.js & Module Federation 基础用法示例](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/module-federation/base)。
196
+ 上述用例可以参考:[Modern.js & Module Federation 基础用法示例](https://github.com/web-infra-dev/modern.js/tree/main/examples/module-federation/base)。
197
197
 
198
198
  ## 相关文档
199
199
 
package/package.json CHANGED
@@ -19,12 +19,12 @@
19
19
  "modern.js",
20
20
  "ultramodern.js"
21
21
  ],
22
- "version": "3.5.0-ultramodern.97",
22
+ "version": "3.5.0-ultramodern.99",
23
23
  "publishConfig": {
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@modern-js/sandpack-react": "npm:@bleedingdev/modern-js-sandpack-react@3.5.0-ultramodern.97",
27
+ "@modern-js/sandpack-react": "npm:@bleedingdev/modern-js-sandpack-react@3.5.0-ultramodern.99",
28
28
  "mermaid": "^11.16.0"
29
29
  },
30
30
  "devDependencies": {