@bleedingdev/modern-js-main-doc 3.4.0-ultramodern.9 → 3.5.0-ultramodern.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/community/blog/v3-release-note.mdx +1 -1
- package/docs/en/configure/app/bff/effect.mdx +116 -3
- package/docs/en/configure/app/bff/runtime-framework.mdx +4 -2
- package/docs/en/configure/app/experiments/source-build.mdx +1 -1
- package/docs/en/configure/app/html/template-parameters.mdx +1 -1
- package/docs/en/configure/app/output/convert-to-rem.mdx +1 -1
- package/docs/en/configure/app/security/check-syntax.mdx +1 -1
- package/docs/en/configure/app/tools/html-plugin.mdx +1 -1
- package/docs/en/configure/app/tools/ts-checker.mdx +20 -1
- package/docs/en/guides/advanced-features/bff/data-platform.mdx +4 -4
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +25 -14
- package/docs/en/guides/advanced-features/bff/function.mdx +4 -0
- package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +1 -1
- package/docs/en/guides/basic-features/debug/using-storybook.mdx +1 -1
- package/docs/en/guides/basic-features/static-assets/json-files.mdx +2 -2
- package/docs/en/guides/get-started/_meta.json +2 -1
- package/docs/en/guides/get-started/ai-coding-agents.mdx +48 -0
- package/docs/en/guides/get-started/ultramodern.mdx +113 -23
- package/docs/en/guides/upgrade/config.mdx +1 -1
- package/docs/en/plugin/introduction.mdx +9 -9
- package/docs/zh/community/blog/v3-release-note.mdx +1 -1
- package/docs/zh/configure/app/bff/effect.mdx +109 -3
- package/docs/zh/configure/app/bff/runtime-framework.mdx +4 -2
- package/docs/zh/configure/app/experiments/source-build.mdx +1 -1
- package/docs/zh/configure/app/html/template-parameters.mdx +1 -1
- package/docs/zh/configure/app/output/convert-to-rem.mdx +1 -1
- package/docs/zh/configure/app/security/check-syntax.mdx +1 -1
- package/docs/zh/configure/app/tools/html-plugin.mdx +1 -1
- package/docs/zh/configure/app/tools/ts-checker.mdx +19 -0
- package/docs/zh/guides/advanced-features/bff/data-platform.mdx +2 -2
- package/docs/zh/guides/advanced-features/bff/frameworks.mdx +24 -14
- package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +1 -1
- package/docs/zh/guides/basic-features/debug/using-storybook.mdx +1 -1
- package/docs/zh/guides/basic-features/static-assets/json-files.mdx +2 -2
- package/docs/zh/guides/get-started/_meta.json +2 -1
- package/docs/zh/guides/get-started/ai-coding-agents.mdx +48 -0
- package/docs/zh/guides/get-started/ultramodern.mdx +92 -19
- package/docs/zh/guides/upgrade/config.mdx +1 -1
- package/docs/zh/plugin/introduction.mdx +9 -9
- package/package.json +2 -2
|
@@ -591,7 +591,7 @@ As Node.js continues to evolve, Node.js 18 has reached EOL. In Modern.js 3.0, we
|
|
|
591
591
|
|
|
592
592
|
#### Storybook Rsbuild
|
|
593
593
|
|
|
594
|
-
In Modern.js 3.0, we implemented Storybook for Modern.js applications based on [Storybook Rsbuild](https://github.com/
|
|
594
|
+
In Modern.js 3.0, we implemented Storybook for Modern.js applications based on [Storybook Rsbuild](https://github.com/rstackjs/storybook-rsbuild).
|
|
595
595
|
|
|
596
596
|
Through a Storybook Addon, we convert and merge Modern.js configuration into Rsbuild configuration, and use Storybook Rsbuild to drive the build, keeping Storybook debugging aligned with development command configurations.
|
|
597
597
|
|
|
@@ -9,6 +9,7 @@ title: effect
|
|
|
9
9
|
```ts
|
|
10
10
|
type BffEffectUserConfig = {
|
|
11
11
|
entry?: string;
|
|
12
|
+
strictEffectApproach?: true;
|
|
12
13
|
openapi?: boolean | { path?: string };
|
|
13
14
|
dataPlatform?: {
|
|
14
15
|
enabled?: boolean;
|
|
@@ -44,6 +45,13 @@ import EnableBFFCaution from "@site-docs-en/components/enable-bff-caution";
|
|
|
44
45
|
|
|
45
46
|
`bff.effect` is only effective when `bff.runtimeFramework` is set to `'effect'`.
|
|
46
47
|
|
|
48
|
+
Generated UltraModern workspaces use this runtime as the only generated HTTP API
|
|
49
|
+
path. The API contract lives at `shared/api.ts`, the server runtime lives at
|
|
50
|
+
`api/index.ts`, clients live under `src/api/*-client.ts`, and generated checks
|
|
51
|
+
reject `api/effect`, `api/lambda`, `shared/effect`, `src/effect`, Hono server
|
|
52
|
+
imports, raw request handlers, manual request parsing, and manual `Response`
|
|
53
|
+
construction in API modules.
|
|
54
|
+
|
|
47
55
|
For Effect v4, TypeScript should use export-map aware module resolution.
|
|
48
56
|
|
|
49
57
|
```json title="tsconfig.json"
|
|
@@ -58,7 +66,7 @@ For Effect v4, TypeScript should use export-map aware module resolution.
|
|
|
58
66
|
## bff.effect.entry
|
|
59
67
|
|
|
60
68
|
- **Type:** `string`
|
|
61
|
-
- **Default:** `<apiDirectory>/
|
|
69
|
+
- **Default:** `<apiDirectory>/index`
|
|
62
70
|
|
|
63
71
|
Specifies the entry module for Effect HttpApi runtime.
|
|
64
72
|
|
|
@@ -67,12 +75,23 @@ export default defineConfig({
|
|
|
67
75
|
bff: {
|
|
68
76
|
runtimeFramework: 'effect',
|
|
69
77
|
effect: {
|
|
70
|
-
entry: './api/
|
|
78
|
+
entry: './api/index',
|
|
71
79
|
},
|
|
72
80
|
},
|
|
73
81
|
});
|
|
74
82
|
```
|
|
75
83
|
|
|
84
|
+
## bff.effect.strictEffectApproach
|
|
85
|
+
|
|
86
|
+
- **Type:** `true`
|
|
87
|
+
- **Default:** `true`
|
|
88
|
+
|
|
89
|
+
Effect BFF modules must expose the strict Effect API surface
|
|
90
|
+
(`defineEffectBff(...)` or `{ api, layer }`) and raw request handlers are
|
|
91
|
+
rejected. Generated UltraModern apps write this marker explicitly and pair it
|
|
92
|
+
with source checks that reject Hono server imports, manual request parsing, and
|
|
93
|
+
manual `Response` construction in generated API modules.
|
|
94
|
+
|
|
76
95
|
## bff.effect.openapi
|
|
77
96
|
|
|
78
97
|
- **Type:** `boolean | { path?: string }`
|
|
@@ -173,4 +192,98 @@ export default defineConfig({
|
|
|
173
192
|
|
|
174
193
|
`batch.flushIntervalMs` controls the client-side micro-batch window in the generated Effect client. `maxConcurrency` and `requestTimeoutMs` are applied by the server batch gateway when dispatching items.
|
|
175
194
|
|
|
176
|
-
The generated `
|
|
195
|
+
The generated `api.client.*` API only exists for loader-materialized `@api/index` imports. Directly importing the server entry (`api/index`) exposes the Effect BFF definition; its `client` property is a placeholder that fails on operation access.
|
|
196
|
+
|
|
197
|
+
## Effect cohort
|
|
198
|
+
|
|
199
|
+
UltraModern-generated workspaces pin the framework-compatible Effect cohort
|
|
200
|
+
through `pnpm-workspace.yaml` overrides. For `3.5.0-ultramodern.1`, generated
|
|
201
|
+
apps use:
|
|
202
|
+
|
|
203
|
+
```yaml
|
|
204
|
+
overrides:
|
|
205
|
+
'@effect/vitest': 4.0.0-beta.89
|
|
206
|
+
effect: 4.0.0-beta.89
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Do not add a different direct `effect` version in an app package. A mismatched
|
|
210
|
+
Effect beta can fail while building layers or HTTP middleware because runtime
|
|
211
|
+
services come from different package instances.
|
|
212
|
+
|
|
213
|
+
## Contract tests
|
|
214
|
+
|
|
215
|
+
Strict Effect APIs should test the declared `HttpApi` contract, not a raw
|
|
216
|
+
request handler. Edge-compatible tests can use the framework helper:
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
import { createEffectBffTestHandler } from '@modern-js/plugin-bff/effect-edge';
|
|
220
|
+
import apiModule from '../api/index';
|
|
221
|
+
|
|
222
|
+
const testApi = await createEffectBffTestHandler({
|
|
223
|
+
module: apiModule,
|
|
224
|
+
prefix: '/api',
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
const response = await testApi.handler(new Request('http://localhost/api/ping'));
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
If you manually compose an Effect web handler in a low-level proof, provide the
|
|
231
|
+
platform services explicitly:
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
import {
|
|
235
|
+
HttpApiBuilder,
|
|
236
|
+
HttpRouter,
|
|
237
|
+
HttpServer,
|
|
238
|
+
Layer,
|
|
239
|
+
} from '@modern-js/plugin-bff/effect-server';
|
|
240
|
+
|
|
241
|
+
const handler = HttpRouter.toWebHandler(
|
|
242
|
+
HttpApiBuilder.layer(api).pipe(
|
|
243
|
+
Layer.provide(apiGroupLayer),
|
|
244
|
+
Layer.provide(HttpServer.layerServices),
|
|
245
|
+
),
|
|
246
|
+
).handler;
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Prefer the generated helper unless the test needs to inspect the low-level
|
|
250
|
+
Effect router composition.
|
|
251
|
+
|
|
252
|
+
## Dynamic CORS
|
|
253
|
+
|
|
254
|
+
For dynamic origin predicates, use Effect HTTP middleware as a layer. In the
|
|
255
|
+
current Effect v4 beta cohort, `HttpRouter.middleware(...)` returns a `Layer`
|
|
256
|
+
directly:
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
import {
|
|
260
|
+
Effect,
|
|
261
|
+
HttpApiBuilder,
|
|
262
|
+
HttpMiddleware,
|
|
263
|
+
HttpRouter,
|
|
264
|
+
Layer,
|
|
265
|
+
} from '@modern-js/plugin-bff/effect-server';
|
|
266
|
+
|
|
267
|
+
const corsLayer = HttpRouter.middleware(
|
|
268
|
+
Effect.succeed(
|
|
269
|
+
HttpMiddleware.cors({
|
|
270
|
+
allowedOrigins: origin =>
|
|
271
|
+
origin.endsWith('.example.com') ? origin : undefined,
|
|
272
|
+
}),
|
|
273
|
+
),
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
const layer = HttpApiBuilder.layer(api).pipe(
|
|
277
|
+
Layer.provide(apiGroupLayer),
|
|
278
|
+
Layer.provide(corsLayer),
|
|
279
|
+
);
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Do not read a `.layer` property from `HttpRouter.middleware(...)`.
|
|
283
|
+
|
|
284
|
+
## Other transports
|
|
285
|
+
|
|
286
|
+
`strictEffectApproach` governs generated HTTP API modules. Effect RPC,
|
|
287
|
+
WebSockets, and other transports remain valid when they are modeled as explicit
|
|
288
|
+
transport surfaces with typed Effect programs. They do not make raw HTTP
|
|
289
|
+
request handlers valid inside generated UltraModern API modules.
|
|
@@ -21,8 +21,10 @@ export default defineConfig({
|
|
|
21
21
|
});
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
- Set to `'effect'` to run BFF only from `api/
|
|
24
|
+
- Set to `'effect'` to run BFF only from `api/index` (Effect HttpApi runtime).
|
|
25
25
|
- Set to `'hono'` to run BFF only from file-convention handlers under `api/lambda/**`.
|
|
26
26
|
|
|
27
27
|
There is no implicit fallback between runtimes. Choose one runtime mode per app.
|
|
28
|
-
Generated UltraModern apps use
|
|
28
|
+
Generated UltraModern apps use strict Effect APIs by default and set
|
|
29
|
+
`bff.effect.strictEffectApproach: true`; `hono` and `api/lambda/**` are not
|
|
30
|
+
valid generated UltraModern HTTP API paths.
|
|
@@ -19,7 +19,7 @@ More detail can see ["Source Code Build Mode"](https://modernjs.dev/en/guides/ad
|
|
|
19
19
|
|
|
20
20
|
### Options
|
|
21
21
|
|
|
22
|
-
`experiments.sourceBuild` is implemented based on [@rsbuild/plugin-source-build](https://github.com/
|
|
22
|
+
`experiments.sourceBuild` is implemented based on [@rsbuild/plugin-source-build](https://github.com/rstackjs/rsbuild-plugin-source-build?tab=readme-ov-file#options). You can pass plugin options like this:
|
|
23
23
|
|
|
24
24
|
```ts
|
|
25
25
|
export default {
|
|
@@ -30,7 +30,7 @@ type DefaultParameters = {
|
|
|
30
30
|
};
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
Define the parameters in the HTML template, corresponding to the `templateParameters` config of [html-rspack-plugin](https://github.com/
|
|
33
|
+
Define the parameters in the HTML template, corresponding to the `templateParameters` config of [html-rspack-plugin](https://github.com/rstackjs/html-rspack-plugin). You can use the config as an object or a function.
|
|
34
34
|
|
|
35
35
|
import RsbuildConfig from '@site-docs-en/components/rsbuild-config-tooltip';
|
|
36
36
|
|
|
@@ -70,4 +70,4 @@ If a syntax error is detected, you can handle it in the following ways:
|
|
|
70
70
|
|
|
71
71
|
### Options
|
|
72
72
|
|
|
73
|
-
`security.checkSyntax` is implemented based on `@rsbuild/plugin-check-syntax`. For specific options, please refer to [@rsbuild/plugin-check-syntax](https://github.com/
|
|
73
|
+
`security.checkSyntax` is implemented based on `@rsbuild/plugin-check-syntax`. For specific options, please refer to [@rsbuild/plugin-check-syntax](https://github.com/rstackjs/rsbuild-plugin-check-syntax).
|
|
@@ -38,7 +38,7 @@ const defaultOptions = {
|
|
|
38
38
|
SSR Application does not enable the `minify.removeComments` configuration, otherwise the SSR rendering will fail.
|
|
39
39
|
:::
|
|
40
40
|
|
|
41
|
-
The configs of [html-rspack-plugin](https://github.com/
|
|
41
|
+
The configs of [html-rspack-plugin](https://github.com/rstackjs/html-rspack-plugin) can be modified through `tools.htmlPlugin`.
|
|
42
42
|
|
|
43
43
|
import RsbuildConfig from '@site-docs-en/components/rsbuild-config-tooltip';
|
|
44
44
|
|
|
@@ -43,7 +43,9 @@ By default, the [@rsbuild/plugin-type-check](https://github.com/rstackjs/rsbuild
|
|
|
43
43
|
|
|
44
44
|
## Example
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
### Object Type
|
|
47
|
+
|
|
48
|
+
When the value of `tsChecker` is an object, it will be deeply merged with the default configuration.
|
|
47
49
|
|
|
48
50
|
```ts
|
|
49
51
|
export default {
|
|
@@ -57,6 +59,23 @@ export default {
|
|
|
57
59
|
};
|
|
58
60
|
```
|
|
59
61
|
|
|
62
|
+
### Function Type
|
|
63
|
+
|
|
64
|
+
When the value of `tsChecker` is a function, the default configuration will be passed as the first argument. You can directly modify the configuration object or return an object as the final configuration.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
export default {
|
|
68
|
+
tools: {
|
|
69
|
+
tsChecker(options) {
|
|
70
|
+
options.async = false;
|
|
71
|
+
return options;
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
> Please refer to [@rsbuild/plugin-type-check](https://github.com/rstackjs/rsbuild-plugin-type-check) for more details.
|
|
78
|
+
|
|
60
79
|
## TypeScript Go by Default
|
|
61
80
|
|
|
62
81
|
Type checking runs on [TypeScript Go](https://github.com/microsoft/typescript-go) (`tsgo`) by default in this fork. The capability is provided by [`ts-checker-rspack-plugin`](https://github.com/rstackjs/ts-checker-rspack-plugin), which is integrated by [`@rsbuild/plugin-type-check`](https://github.com/rstackjs/rsbuild-plugin-type-check), and reduces type-checking time by about 5-10x.
|
|
@@ -4,7 +4,7 @@ title: Data Platform
|
|
|
4
4
|
|
|
5
5
|
# Data Platform
|
|
6
6
|
|
|
7
|
-
Modern.js Effect
|
|
7
|
+
Modern.js Effect API runtime now supports a request-envelope based data platform contract for safer and more predictable data orchestration in complex applications such as Module Federation and micro frontends.
|
|
8
8
|
|
|
9
9
|
## What it solves
|
|
10
10
|
|
|
@@ -57,11 +57,11 @@ export default defineConfig({
|
|
|
57
57
|
|
|
58
58
|
Envelope validation is enabled by default but does not require an envelope unless `requireEnvelope` is set. Origin validation is enabled by default; set `validateOrigin: false` to skip comparing the envelope origin against the incoming `Origin` header, or the request URL origin when the header is absent.
|
|
59
59
|
|
|
60
|
-
## Generated
|
|
60
|
+
## Generated API client behavior
|
|
61
61
|
|
|
62
|
-
When using the generated
|
|
62
|
+
When using the generated API client (`@api/index`), Modern.js automatically attaches a serialized data envelope header (`x-modernjs-data-envelope`) for same-origin requests.
|
|
63
63
|
|
|
64
|
-
The generated client is loader-materialized. Import it from `@api/
|
|
64
|
+
The generated client is loader-materialized. Import it from `@api/index` in browser or client-bundled code; direct imports of the server entry (`api/index`) expose the Effect API definition and only provide a placeholder `client`.
|
|
65
65
|
|
|
66
66
|
The envelope includes:
|
|
67
67
|
|
|
@@ -7,11 +7,20 @@ title: Runtime Framework
|
|
|
7
7
|
|
|
8
8
|
Modern.js supports two BFF runtime frameworks:
|
|
9
9
|
|
|
10
|
-
- `effect` (default): use [Effect HttpApi](https://effect.website/) runtime from `api/
|
|
10
|
+
- `effect` (default): use [Effect HttpApi](https://effect.website/) runtime from `api/index`.
|
|
11
11
|
- `hono`: use file-convention BFF handlers from `api/lambda/**`.
|
|
12
12
|
|
|
13
13
|
`effect` and `hono` are strict runtime modes. There is no automatic fallback between them.
|
|
14
14
|
|
|
15
|
+
::::info
|
|
16
|
+
This page documents generic Modern.js runtime support. Generated UltraModern
|
|
17
|
+
workspaces always use the `effect` runtime with
|
|
18
|
+
`bff.effect.strictEffectApproach: true`. Add or change generated UltraModern
|
|
19
|
+
HTTP API work through `shared/api.ts` and `api/index.ts`; do not add
|
|
20
|
+
Hono/file-convention handlers, raw request parsing, or manual `Response`
|
|
21
|
+
construction inside those workspaces.
|
|
22
|
+
::::
|
|
23
|
+
|
|
15
24
|
## Switch to Effect runtime
|
|
16
25
|
|
|
17
26
|
```ts title="modern.config.ts"
|
|
@@ -23,6 +32,8 @@ export default defineConfig({
|
|
|
23
32
|
bff: {
|
|
24
33
|
runtimeFramework: 'effect',
|
|
25
34
|
effect: {
|
|
35
|
+
entry: './api/index',
|
|
36
|
+
strictEffectApproach: true,
|
|
26
37
|
openapi: {
|
|
27
38
|
path: '/openapi.json',
|
|
28
39
|
},
|
|
@@ -33,7 +44,7 @@ export default defineConfig({
|
|
|
33
44
|
|
|
34
45
|
Define a shared Effect HttpApi contract (for type-safe client + server):
|
|
35
46
|
|
|
36
|
-
```ts title="shared/
|
|
47
|
+
```ts title="shared/api.ts"
|
|
37
48
|
import {
|
|
38
49
|
HttpApi,
|
|
39
50
|
HttpApiEndpoint,
|
|
@@ -41,18 +52,18 @@ import {
|
|
|
41
52
|
Schema,
|
|
42
53
|
} from '@modern-js/plugin-bff/effect-client';
|
|
43
54
|
|
|
44
|
-
export const
|
|
55
|
+
export const bffApi = HttpApi.make('MyApi').add(
|
|
45
56
|
HttpApiGroup.make('hello').add(
|
|
46
|
-
HttpApiEndpoint.get('ping', '/
|
|
57
|
+
HttpApiEndpoint.get('ping', '/ping', {
|
|
47
58
|
success: Schema.String,
|
|
48
59
|
}),
|
|
49
60
|
),
|
|
50
61
|
);
|
|
51
62
|
```
|
|
52
63
|
|
|
53
|
-
Implement your Effect
|
|
64
|
+
Implement your Effect API entry at `api/index.ts`:
|
|
54
65
|
|
|
55
|
-
```ts title="api/
|
|
66
|
+
```ts title="api/index.ts"
|
|
56
67
|
import {
|
|
57
68
|
Schema,
|
|
58
69
|
Effect,
|
|
@@ -61,7 +72,7 @@ import {
|
|
|
61
72
|
Layer,
|
|
62
73
|
ServiceMap,
|
|
63
74
|
} from '@modern-js/plugin-bff/effect-server';
|
|
64
|
-
import {
|
|
75
|
+
import { bffApi } from '../shared/api';
|
|
65
76
|
|
|
66
77
|
class GreetingUnavailableError extends Schema.TaggedError<GreetingUnavailableError>()(
|
|
67
78
|
'GreetingUnavailableError',
|
|
@@ -87,7 +98,7 @@ class GreetingService extends ServiceMap.Service<GreetingService>()('GreetingSer
|
|
|
87
98
|
static readonly layer = Layer.effect(this, this.make);
|
|
88
99
|
}
|
|
89
100
|
|
|
90
|
-
const group = HttpApiBuilder.group(
|
|
101
|
+
const group = HttpApiBuilder.group(bffApi, 'hello', handlers =>
|
|
91
102
|
handlers.handle('ping', () =>
|
|
92
103
|
GreetingService.use(service => service.hello()).pipe(
|
|
93
104
|
Effect.catchTag('GreetingUnavailableError', error =>
|
|
@@ -97,23 +108,23 @@ const group = HttpApiBuilder.group(bffEffectApi, 'hello', handlers =>
|
|
|
97
108
|
),
|
|
98
109
|
);
|
|
99
110
|
|
|
100
|
-
const layer = HttpApiBuilder.layer(
|
|
111
|
+
const layer = HttpApiBuilder.layer(bffApi).pipe(
|
|
101
112
|
Layer.provide(group),
|
|
102
113
|
Layer.provide(GreetingService.layer),
|
|
103
114
|
);
|
|
104
115
|
|
|
105
|
-
export default defineEffectBff({ api:
|
|
116
|
+
export default defineEffectBff({ api: bffApi, layer });
|
|
106
117
|
```
|
|
107
118
|
|
|
108
|
-
Call Effect endpoints from browser code via `@api/
|
|
119
|
+
Call Effect endpoints from browser code via `@api/index`:
|
|
109
120
|
|
|
110
121
|
```ts title="src/routes/page.tsx"
|
|
111
|
-
import
|
|
122
|
+
import api from '@api/index';
|
|
112
123
|
|
|
113
|
-
const response = await
|
|
124
|
+
const response = await api.client.hello.ping({});
|
|
114
125
|
```
|
|
115
126
|
|
|
116
|
-
The `
|
|
127
|
+
The `api.client.*` surface is materialized by the BFF loader for `@api/index` imports. Do not import `api/index` directly and expect `client` to run in server code, scripts, or tests; direct entry imports expose the server runtime definition, and `client` is only a typed placeholder there.
|
|
117
128
|
|
|
118
129
|
import Hono from '@site-docs-en/components/hono';
|
|
119
130
|
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
In a Modern.js application, developers can define API files under the `api/lambda` directory and export API functions from these files. In the frontend code, these API functions can be directly invoked by importing the file, which initiates the API requests.
|
|
4
4
|
|
|
5
|
+
:::warning
|
|
6
|
+
`api/lambda/**` is the Hono/file-function compatibility runtime. New UltraModern generated API work should use the strict Effect runtime with `api/index.ts`, `shared/api.ts`, `defineEffectBff(...)`, and Effect `HttpApi` schemas instead.
|
|
7
|
+
:::
|
|
8
|
+
|
|
5
9
|
This invocation method is called **unified invocation**, where developers do not need to write glue code for the frontend and backend separately, thereby ensuring type safety across both.
|
|
6
10
|
|
|
7
11
|
## Enable BFF
|
|
@@ -92,7 +92,7 @@ export default {
|
|
|
92
92
|
};
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
See details in [plugin-image-compress](https://github.com/
|
|
95
|
+
See details in [plugin-image-compress](https://github.com/rstackjs/rsbuild-plugin-image-compress).
|
|
96
96
|
|
|
97
97
|
## Split Chunk
|
|
98
98
|
|
|
@@ -97,4 +97,4 @@ Now you can request the path configured in `bff.prefix`; if not configured, use
|
|
|
97
97
|
|
|
98
98
|
## Example
|
|
99
99
|
|
|
100
|
-
You can check out the [example](https://github.com/
|
|
100
|
+
You can check out the [example](https://github.com/rstackjs/storybook-rsbuild/tree/main/sandboxes/modernjs-react) to learn how to use Storybook in Modern.js.
|
|
@@ -38,7 +38,7 @@ import { name } from './example.json';
|
|
|
38
38
|
|
|
39
39
|
YAML is a data serialization language commonly used for writing configuration files.
|
|
40
40
|
|
|
41
|
-
You can configure the [YAML plugin](https://github.com/
|
|
41
|
+
You can configure the [YAML plugin](https://github.com/rstackjs/rsbuild-plugin-yaml) in `modern.config.ts` to support importing `.yaml` or `.yml` files, they will be automatically converted to JSON format.
|
|
42
42
|
|
|
43
43
|
```ts
|
|
44
44
|
import { defineConfig } from '@modern-js/app-tools';
|
|
@@ -85,7 +85,7 @@ declare module '*.yml' {
|
|
|
85
85
|
|
|
86
86
|
Toml is a semantically explicit, easy-to-read configuration file format.
|
|
87
87
|
|
|
88
|
-
You can configure the [TOML plugin](https://github.com/
|
|
88
|
+
You can configure the [TOML plugin](https://github.com/rstackjs/rsbuild-plugin-toml) in `modern.config.ts` to support importing `.toml` files, it will be automatically converted to JSON format.
|
|
89
89
|
|
|
90
90
|
```ts
|
|
91
91
|
import { defineConfig } from '@modern-js/app-tools';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AI Tools
|
|
3
|
+
sidebar_position: 6
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Modern.js For AI
|
|
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.
|
|
9
|
+
|
|
10
|
+
## llms.txt
|
|
11
|
+
|
|
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`:
|
|
13
|
+
|
|
14
|
+
- Index: [`https://modernjs.dev/llms.txt`](https://modernjs.dev/llms.txt)
|
|
15
|
+
- Full text: `https://modernjs.dev/llms-full.txt` (large — fetch on demand)
|
|
16
|
+
|
|
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.
|
|
18
|
+
|
|
19
|
+
## Skills
|
|
20
|
+
|
|
21
|
+
Skills are on-demand AI capabilities following the [Agent Skills open standard](https://github.com/vercel-labs/skills). User-facing Skills:
|
|
22
|
+
|
|
23
|
+
| Skill | Identifier | Description |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| Upgrade to v3 | `modernjs-migrate-to-v3` | Migrate a v2 app to v3: safe rewrites + manual checklist + migration report |
|
|
26
|
+
| Enable features | `modernjs-feature-enable` | Enable BFF / SSG / styled-components for v3 apps, and scaffold Tailwind CSS / custom Web Server |
|
|
27
|
+
|
|
28
|
+
> Skills are not force-installed or implicitly installed — you install them explicitly. RSC and micro-frontend setups are configuration or architecture decisions, not one-click `modernjs-feature-enable` actions.
|
|
29
|
+
|
|
30
|
+
## Installing Skills
|
|
31
|
+
|
|
32
|
+
Modern.js user-facing Skills live in the repo's root `skills/` directory and follow the [Agent Skills open standard](https://github.com/vercel-labs/skills). The recommended way is the standard `skills` CLI, installing straight from GitHub:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# List installable Skills
|
|
36
|
+
npx skills add web-infra-dev/modern.js --list
|
|
37
|
+
|
|
38
|
+
# Install a single Skill into your agent directory (--agent: claude-code / codex / cursor / ...)
|
|
39
|
+
npx skills add web-infra-dev/modern.js --skill modernjs-migrate-to-v3 --agent codex -y
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
It installs the entire Skill directory (`SKILL.md` + `scripts/` + `references/`) into the corresponding agent directory, ready to trigger there.
|
|
43
|
+
|
|
44
|
+
> To pin a specific version, append `#<ref>` (a tag, branch, or commit) to the repo — it installs the Skill as of that ref (replace `<tag>` with a release tag that contains this Skill):
|
|
45
|
+
>
|
|
46
|
+
> ```bash
|
|
47
|
+
> npx skills add web-infra-dev/modern.js#<tag> --skill modernjs-migrate-to-v3 --agent codex -y
|
|
48
|
+
> ```
|