@modern-js/app-tools 3.9.3 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +54 -2
- package/dist/cjs/compat/hooks.js +0 -5
- package/dist/cjs/compat/index.js +0 -5
- package/dist/cjs/compat/utils.js +0 -5
- package/dist/cjs/plugins/initialize/index.js +0 -1
- package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.mjs +54 -2
- package/dist/esm/compat/hooks.mjs +0 -5
- package/dist/esm/compat/index.mjs +0 -5
- package/dist/esm/compat/utils.mjs +0 -5
- package/dist/esm/plugins/initialize/index.mjs +0 -1
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.mjs +54 -2
- package/dist/esm-node/compat/hooks.mjs +0 -5
- package/dist/esm-node/compat/index.mjs +0 -5
- package/dist/esm-node/compat/utils.mjs +0 -5
- package/dist/esm-node/plugins/initialize/index.mjs +0 -1
- package/dist/types/types/config/index.d.ts +0 -2
- package/dist/types/types/config/tools.d.ts +0 -8
- package/docs/apis/app/commands.md +2 -0
- package/docs/apis/app/hooks/api/lambda.md +2 -0
- package/docs/apis/app/hooks/config/favicon.md +2 -0
- package/docs/apis/app/hooks/config/html.md +2 -0
- package/docs/apis/app/hooks/config/icon.md +2 -0
- package/docs/apis/app/hooks/config/mock.md +2 -0
- package/docs/apis/app/hooks/config/public.md +2 -0
- package/docs/apis/app/hooks/config/upload.md +3 -3
- package/docs/apis/app/hooks/modern-config.md +2 -0
- package/docs/apis/app/hooks/server/server.md +2 -0
- package/docs/apis/app/hooks/shared.md +2 -0
- package/docs/apis/app/hooks/src/app.md +2 -0
- package/docs/apis/app/hooks/src/entry.md +2 -0
- package/docs/apis/app/hooks/src/entry.server.md +2 -0
- package/docs/apis/app/hooks/src/modern.runtime.md +2 -0
- package/docs/apis/app/hooks/src/routes.md +2 -0
- package/docs/apis/app/hooks/src/server.md +2 -0
- package/docs/apis/app/runtime/bff/use-hono-context.md +2 -0
- package/docs/apis/app/runtime/core/create-root.md +5 -1
- package/docs/apis/app/runtime/core/render.md +7 -2
- package/docs/apis/app/runtime/core/runtime-context.md +18 -16
- package/docs/apis/app/runtime/router/router.md +11 -6
- package/docs/apis/app/runtime/ssr/no-ssr.md +2 -0
- package/docs/apis/app/runtime/ssr/renderStreaming.md +2 -0
- package/docs/apis/app/runtime/ssr/renderString.md +2 -0
- package/docs/apis/app/runtime/ssr/requestHandler.md +2 -0
- package/docs/apis/app/runtime/utility/css-in-js.md +2 -0
- package/docs/apis/app/runtime/utility/head.md +2 -0
- package/docs/apis/app/runtime/utility/loadable.md +2 -0
- package/docs/community/blog/2022-0708-updates.md +2 -0
- package/docs/community/blog/2022-0910-updates.md +2 -0
- package/docs/community/blog/overview.md +2 -0
- package/docs/community/blog/v2-release-note.md +2 -0
- package/docs/community/blog/v3-release-note.md +18 -13
- package/docs/community/contributing-guide.md +17 -33
- package/docs/community/releases.md +2 -0
- package/docs/community/showcase.md +2 -0
- package/docs/community/team.md +2 -0
- package/docs/configure/app/bff/cross-project.md +2 -0
- package/docs/configure/app/bff/prefix.md +2 -0
- package/docs/configure/app/builder-plugins.md +2 -0
- package/docs/configure/app/dev/asset-prefix.md +2 -0
- package/docs/configure/app/dev/before-start-url.md +2 -0
- package/docs/configure/app/dev/client.md +2 -0
- package/docs/configure/app/dev/hmr.md +2 -0
- package/docs/configure/app/dev/host.md +2 -0
- package/docs/configure/app/dev/https.md +2 -0
- package/docs/configure/app/dev/lazy-compilation.md +19 -1
- package/docs/configure/app/dev/live-reload.md +2 -0
- package/docs/configure/app/dev/mock-dir.md +2 -0
- package/docs/configure/app/dev/progress-bar.md +2 -0
- package/docs/configure/app/dev/server.md +2 -0
- package/docs/configure/app/dev/setup-middlewares.md +2 -0
- package/docs/configure/app/dev/start-url.md +2 -0
- package/docs/configure/app/dev/watch-files.md +2 -0
- package/docs/configure/app/dev/write-to-disk.md +2 -0
- package/docs/configure/app/experiments/source-build.md +2 -0
- package/docs/configure/app/html/app-icon.md +2 -0
- package/docs/configure/app/html/crossorigin.md +2 -0
- package/docs/configure/app/html/favicon.md +2 -0
- package/docs/configure/app/html/inject.md +2 -0
- package/docs/configure/app/html/meta.md +2 -0
- package/docs/configure/app/html/mount-id.md +2 -0
- package/docs/configure/app/html/output-structure.md +2 -0
- package/docs/configure/app/html/script-loading.md +2 -0
- package/docs/configure/app/html/tags.md +2 -0
- package/docs/configure/app/html/template-parameters.md +2 -0
- package/docs/configure/app/html/template.md +2 -0
- package/docs/configure/app/html/title.md +2 -0
- package/docs/configure/app/output/asset-prefix.md +2 -0
- package/docs/configure/app/output/assets-retry.md +2 -0
- package/docs/configure/app/output/charset.md +2 -0
- package/docs/configure/app/output/clean-dist-path.md +2 -0
- package/docs/configure/app/output/convert-to-rem.md +2 -0
- package/docs/configure/app/output/copy.md +2 -0
- package/docs/configure/app/output/css-modules.md +3 -5
- package/docs/configure/app/output/data-uri-limit.md +2 -0
- package/docs/configure/app/output/disable-css-module-extension.md +2 -0
- package/docs/configure/app/output/disable-inline-runtime-chunk.md +2 -0
- package/docs/configure/app/output/disable-svgr.md +2 -0
- package/docs/configure/app/output/disable-ts-checker.md +2 -0
- package/docs/configure/app/output/dist-path.md +2 -0
- package/docs/configure/app/output/enable-asset-manifest.md +2 -0
- package/docs/configure/app/output/enable-css-module-tsdeclaration.md +2 -0
- package/docs/configure/app/output/enable-inline-route-manifests.md +2 -0
- package/docs/configure/app/output/externals.md +2 -0
- package/docs/configure/app/output/filename-hash.md +2 -0
- package/docs/configure/app/output/filename.md +2 -0
- package/docs/configure/app/output/inject-styles.md +2 -0
- package/docs/configure/app/output/inline-scripts.md +3 -2
- package/docs/configure/app/output/inline-styles.md +3 -2
- package/docs/configure/app/output/legal-comments.md +2 -0
- package/docs/configure/app/output/minify.md +2 -0
- package/docs/configure/app/output/override-browserslist.md +2 -0
- package/docs/configure/app/output/polyfill.md +2 -0
- package/docs/configure/app/output/source-map.md +2 -0
- package/docs/configure/app/output/split-route-chunks.md +3 -1
- package/docs/configure/app/output/ssg.md +2 -0
- package/docs/configure/app/output/ssgByEntries.md +2 -0
- package/docs/configure/app/output/svg-default-export.md +2 -0
- package/docs/configure/app/output/temp-dir.md +2 -0
- package/docs/configure/app/performance/build-cache.md +2 -0
- package/docs/configure/app/performance/chunk-split.md +3 -4
- package/docs/configure/app/performance/dns-prefetch.md +2 -0
- package/docs/configure/app/performance/preconnect.md +2 -0
- package/docs/configure/app/performance/prefetch.md +2 -0
- package/docs/configure/app/performance/preload.md +2 -0
- package/docs/configure/app/performance/print-file-size.md +2 -0
- package/docs/configure/app/performance/profile.md +2 -0
- package/docs/configure/app/performance/remove-console.md +2 -0
- package/docs/configure/app/performance/remove-moment-locale.md +2 -0
- package/docs/configure/app/plugins.md +2 -0
- package/docs/configure/app/resolve/alias-strategy.md +2 -0
- package/docs/configure/app/resolve/alias.md +2 -0
- package/docs/configure/app/resolve/condition-names.md +2 -0
- package/docs/configure/app/resolve/dedupe.md +2 -0
- package/docs/configure/app/resolve/extensions.md +2 -0
- package/docs/configure/app/runtime/0-intro.md +2 -0
- package/docs/configure/app/runtime/plugins.md +8 -4
- package/docs/configure/app/runtime/router.md +2 -0
- package/docs/configure/app/security/check-syntax.md +2 -0
- package/docs/configure/app/security/nonce.md +2 -0
- package/docs/configure/app/security/sri.md +2 -0
- package/docs/configure/app/server/base-url.md +2 -0
- package/docs/configure/app/server/port.md +2 -0
- package/docs/configure/app/server/public-routes.md +2 -0
- package/docs/configure/app/server/routes.md +2 -0
- package/docs/configure/app/server/rsc.md +2 -0
- package/docs/configure/app/server/ssr-by-entries.md +2 -0
- package/docs/configure/app/server/ssr.md +3 -1
- package/docs/configure/app/server/tsconfig-path.md +4 -2
- package/docs/configure/app/source/alias-strategy.md +2 -0
- package/docs/configure/app/source/alias.md +2 -0
- package/docs/configure/app/source/config-dir.md +2 -0
- package/docs/configure/app/source/decorators.md +2 -0
- package/docs/configure/app/source/define.md +2 -0
- package/docs/configure/app/source/disable-default-entries.md +2 -0
- package/docs/configure/app/source/enable-async-entry.md +2 -0
- package/docs/configure/app/source/enable-async-pre-entry.md +2 -0
- package/docs/configure/app/source/entries-dir.md +2 -0
- package/docs/configure/app/source/entries.md +2 -0
- package/docs/configure/app/source/exclude.md +2 -0
- package/docs/configure/app/source/global-vars.md +2 -0
- package/docs/configure/app/source/include.md +2 -0
- package/docs/configure/app/source/main-entry-name.md +2 -0
- package/docs/configure/app/source/pre-entry.md +2 -0
- package/docs/configure/app/source/react-compiler.md +2 -0
- package/docs/configure/app/source/transform-import.md +2 -0
- package/docs/configure/app/split-chunks.md +2 -0
- package/docs/configure/app/tools/autoprefixer.md +2 -0
- package/docs/configure/app/tools/bundler-chain.md +2 -0
- package/docs/configure/app/tools/css-extract.md +2 -0
- package/docs/configure/app/tools/css-loader.md +2 -0
- package/docs/configure/app/tools/dev-server.md +2 -0
- package/docs/configure/app/tools/html-plugin.md +2 -0
- package/docs/configure/app/tools/less.md +2 -0
- package/docs/configure/app/tools/lightningcss-loader.md +2 -0
- package/docs/configure/app/tools/minify-css.md +2 -0
- package/docs/configure/app/tools/postcss.md +2 -0
- package/docs/configure/app/tools/rspack.md +2 -0
- package/docs/configure/app/tools/sass.md +8 -6
- package/docs/configure/app/tools/style-loader.md +2 -0
- package/docs/configure/app/tools/svgr.md +2 -0
- package/docs/configure/app/tools/swc.md +2 -0
- package/docs/configure/app/tools/ts-checker.md +2 -0
- package/docs/configure/app/usage.md +3 -5
- package/docs/guides/advanced-features/bff/cross-project.md +6 -4
- package/docs/guides/advanced-features/bff/extend-server.md +2 -0
- package/docs/guides/advanced-features/bff/frameworks.md +2 -0
- package/docs/guides/advanced-features/bff/function.md +2 -0
- package/docs/guides/advanced-features/bff/operators.md +2 -0
- package/docs/guides/advanced-features/bff/sdk.md +2 -0
- package/docs/guides/advanced-features/bff/upload.md +2 -0
- package/docs/guides/advanced-features/bff.md +2 -0
- package/docs/guides/advanced-features/build-performance.md +2 -0
- package/docs/guides/advanced-features/compatibility.md +2 -0
- package/docs/guides/advanced-features/international/advanced.md +3 -1
- package/docs/guides/advanced-features/international/api.md +21 -13
- package/docs/guides/advanced-features/international/best-practices.md +17 -15
- package/docs/guides/advanced-features/international/configuration.md +3 -1
- package/docs/guides/advanced-features/international/locale-detection.md +15 -4
- package/docs/guides/advanced-features/international/quick-start.md +2 -0
- package/docs/guides/advanced-features/international/resource-loading.md +11 -7
- package/docs/guides/advanced-features/international/routing.md +5 -1
- package/docs/guides/advanced-features/international.md +2 -0
- package/docs/guides/advanced-features/low-level.md +2 -0
- package/docs/guides/advanced-features/page-performance/code-split.md +2 -0
- package/docs/guides/advanced-features/page-performance/inline-assets.md +2 -0
- package/docs/guides/advanced-features/page-performance/optimize-bundle.md +2 -0
- package/docs/guides/advanced-features/page-performance/react-compiler.md +2 -0
- package/docs/guides/advanced-features/server-monitor/logger.md +2 -0
- package/docs/guides/advanced-features/server-monitor/metrics.md +2 -0
- package/docs/guides/advanced-features/server-monitor/monitors.md +3 -3
- package/docs/guides/advanced-features/source-build.md +3 -1
- package/docs/guides/advanced-features/web-server.md +5 -3
- package/docs/guides/basic-features/alias.md +2 -0
- package/docs/guides/basic-features/css/css-in-js.md +2 -0
- package/docs/guides/basic-features/css/css-modules.md +2 -0
- package/docs/guides/basic-features/css/css.md +2 -0
- package/docs/guides/basic-features/css/tailwindcss.md +2 -0
- package/docs/guides/basic-features/data/data-cache.md +2 -0
- package/docs/guides/basic-features/data/data-fetch.md +3 -3
- package/docs/guides/basic-features/data/data-write.md +25 -28
- package/docs/guides/basic-features/debug/mock.md +4 -2
- package/docs/guides/basic-features/debug/proxy.md +2 -0
- package/docs/guides/basic-features/debug/rsdoctor.md +2 -0
- package/docs/guides/basic-features/debug/using-storybook.md +6 -4
- package/docs/guides/basic-features/deploy.md +2 -0
- package/docs/guides/basic-features/env-vars.md +2 -0
- package/docs/guides/basic-features/html.md +4 -3
- package/docs/guides/basic-features/output-files.md +3 -1
- package/docs/guides/basic-features/render/before-render.md +2 -0
- package/docs/guides/basic-features/render/overview.md +2 -0
- package/docs/guides/basic-features/render/rsc.md +12 -2
- package/docs/guides/basic-features/render/ssg.md +2 -0
- package/docs/guides/basic-features/render/ssr-cache.md +2 -0
- package/docs/guides/basic-features/render/ssr.md +10 -12
- package/docs/guides/basic-features/render/streaming-ssr.md +4 -1
- package/docs/guides/basic-features/routes/config-routes.md +54 -54
- package/docs/guides/basic-features/routes/routes.md +2 -0
- package/docs/guides/basic-features/static-assets/json-files.md +2 -0
- package/docs/guides/basic-features/static-assets/svg-assets.md +2 -0
- package/docs/guides/basic-features/static-assets/wasm-assets.md +2 -0
- package/docs/guides/basic-features/static-assets.md +2 -0
- package/docs/guides/basic-features/testing/playwright.md +8 -6
- package/docs/guides/basic-features/testing/rstest.md +7 -5
- package/docs/guides/concept/builder.md +2 -0
- package/docs/guides/concept/entries.md +2 -0
- package/docs/guides/concept/server.md +2 -0
- package/docs/guides/get-started/ai-coding-agents.md +5 -3
- package/docs/guides/get-started/glossary.md +2 -0
- package/docs/guides/get-started/introduction.md +2 -0
- package/docs/guides/get-started/quick-start.md +13 -5
- package/docs/guides/get-started/tech-stack.md +2 -0
- package/docs/guides/get-started/upgrade.md +2 -0
- package/docs/guides/topic-detail/module-federation/application.md +2 -0
- package/docs/guides/topic-detail/module-federation/deploy.md +4 -2
- package/docs/guides/topic-detail/module-federation/i18n.md +2 -0
- package/docs/guides/topic-detail/module-federation/introduce.md +2 -0
- package/docs/guides/topic-detail/module-federation/ssr.md +2 -0
- package/docs/guides/topic-detail/module-federation/usage.md +2 -0
- package/docs/guides/troubleshooting/builder.md +2 -0
- package/docs/guides/troubleshooting/cli.md +2 -0
- package/docs/guides/troubleshooting/dependencies.md +2 -0
- package/docs/guides/troubleshooting/hmr.md +2 -0
- package/docs/guides/upgrade/config.md +14 -0
- package/docs/guides/upgrade/entry.md +2 -0
- package/docs/guides/upgrade/other.md +2 -0
- package/docs/guides/upgrade/overview.md +2 -0
- package/docs/guides/upgrade/tailwindcss.md +2 -0
- package/docs/guides/upgrade/web-server.md +25 -6
- package/docs/index.md +2 -0
- package/docs/llms.txt +5 -5
- package/docs/plugin/cli-plugins/api.md +2 -0
- package/docs/plugin/cli-plugins/life-cycle.md +2 -0
- package/docs/plugin/introduction.md +2 -0
- package/docs/plugin/official/cli-plugins/plugin-bff.md +2 -0
- package/docs/plugin/official/cli-plugins/plugin-ssg.md +2 -0
- package/docs/plugin/official/cli-plugins/plugin-styled-components.md +2 -0
- package/docs/plugin/official/cli-plugins.md +2 -0
- package/docs/plugin/plugin-system.md +3 -3
- package/docs/plugin/runtime-plugins/api.md +2 -0
- package/docs/plugin/runtime-plugins/life-cycle.md +2 -0
- package/docs/plugin/server-plugins/api.md +2 -0
- package/docs/plugin/server-plugins/life-cycle.md +2 -0
- package/docs/tutorials/examples/csr-auth.md +2 -0
- package/docs/tutorials/foundations/introduction.md +2 -0
- package/lib/types.d.ts +0 -1
- package/package.json +16 -17
- package/{rslib.config.mts → rstack.config.mts} +4 -4
- package/dist/cjs/types/config/testing.js +0 -18
- package/dist/esm/types/config/testing.mjs +0 -0
- package/dist/esm-node/types/config/testing.mjs +0 -1
- package/dist/types/types/config/testing.d.ts +0 -8
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Config Routes
|
|
2
4
|
|
|
3
5
|
By default, Modern.js recommends using [Convention Routes](/guides/basic-features/routes/routes.md) as the way to define routes. At the same time, Modern.js also provides a config-based routing capability that can be used together with convention routes or used separately.
|
|
@@ -17,13 +19,11 @@ Config routes are particularly useful in the following scenarios:
|
|
|
17
19
|
In the `src` directory or each entry directory, you can define a `modern.routes.ts` file to configure routes:
|
|
18
20
|
|
|
19
21
|
```ts
|
|
20
|
-
import { defineRoutes } from '@modern-js/runtime/config-routes'
|
|
22
|
+
import { defineRoutes } from '@modern-js/runtime/config-routes';
|
|
21
23
|
|
|
22
24
|
export default defineRoutes(({ route, layout, page, $ }, fileRoutes) => {
|
|
23
|
-
return [
|
|
24
|
-
|
|
25
|
-
]
|
|
26
|
-
})
|
|
25
|
+
return [route('home.tsx', '/')];
|
|
26
|
+
});
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
### Function Signature Description
|
|
@@ -69,24 +69,24 @@ The `route` function is a general-purpose route configuration function that auto
|
|
|
69
69
|
export default defineRoutes(({ route }, fileRoutes) => {
|
|
70
70
|
return [
|
|
71
71
|
// When no child routes, automatically generates page route
|
|
72
|
-
route(
|
|
73
|
-
route(
|
|
72
|
+
route('home.tsx', '/'),
|
|
73
|
+
route('about.tsx', 'about'),
|
|
74
74
|
|
|
75
75
|
// When has child routes, automatically generates layout route
|
|
76
76
|
// dashboard/layout.tsx needs to contain <Outlet> to render child routes
|
|
77
|
-
route(
|
|
78
|
-
route(
|
|
79
|
-
route(
|
|
77
|
+
route('dashboard/layout.tsx', 'dashboard', [
|
|
78
|
+
route('dashboard/overview.tsx', 'overview'), // Generated path: /dashboard/overview
|
|
79
|
+
route('dashboard/settings.tsx', 'settings'), // Generated path: /dashboard/settings
|
|
80
80
|
]),
|
|
81
81
|
|
|
82
82
|
// Dynamic routes
|
|
83
|
-
route(
|
|
83
|
+
route('products/detail.tsx', 'products/:id'),
|
|
84
84
|
|
|
85
85
|
// Multiple paths pointing to the same component
|
|
86
|
-
route(
|
|
87
|
-
route(
|
|
88
|
-
]
|
|
89
|
-
})
|
|
86
|
+
route('user/profile.tsx', 'user'),
|
|
87
|
+
route('user/profile.tsx', 'profile'),
|
|
88
|
+
];
|
|
89
|
+
});
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
**Use cases**:
|
|
@@ -102,12 +102,12 @@ The `layout` function is specifically used to configure layout routes, always ge
|
|
|
102
102
|
export default defineRoutes(({ layout, page }, fileRoutes) => {
|
|
103
103
|
return [
|
|
104
104
|
// Generate layout route with path "/auth", must contain child routes
|
|
105
|
-
layout(
|
|
106
|
-
page(
|
|
107
|
-
page(
|
|
105
|
+
layout('auth/layout.tsx', 'auth', [
|
|
106
|
+
page('auth/login/page.tsx', 'login'), // Generated path: /auth/login
|
|
107
|
+
page('auth/register/page.tsx', 'register'), // Generated path: /auth/register
|
|
108
108
|
]),
|
|
109
|
-
]
|
|
110
|
-
})
|
|
109
|
+
];
|
|
110
|
+
});
|
|
111
111
|
```
|
|
112
112
|
|
|
113
113
|
**Use cases**:
|
|
@@ -123,12 +123,12 @@ The `page` function is specifically used to configure page routes, always genera
|
|
|
123
123
|
```ts
|
|
124
124
|
export default defineRoutes(({ layout, page }, fileRoutes) => {
|
|
125
125
|
return [
|
|
126
|
-
layout(
|
|
127
|
-
page(
|
|
128
|
-
page(
|
|
126
|
+
layout('dashboard/layout.tsx', 'dashboard', [
|
|
127
|
+
page('dashboard/overview.tsx', 'overview'), // Generated path: /dashboard/overview
|
|
128
|
+
page('dashboard/settings.tsx', 'settings'), // Generated path: /dashboard/settings
|
|
129
129
|
]),
|
|
130
|
-
]
|
|
131
|
-
})
|
|
130
|
+
];
|
|
131
|
+
});
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
**Use cases**:
|
|
@@ -144,13 +144,13 @@ The `$` function is specifically used to configure wildcard routes for handling
|
|
|
144
144
|
```ts
|
|
145
145
|
export default defineRoutes(({ layout, page, $ }, fileRoutes) => {
|
|
146
146
|
return [
|
|
147
|
-
layout(
|
|
148
|
-
page(
|
|
149
|
-
page(
|
|
150
|
-
$(
|
|
147
|
+
layout('blog/layout.tsx', 'blog', [
|
|
148
|
+
page('blog/page.tsx', ''), // Generated path: /blog
|
|
149
|
+
page('blog/[id]/page.tsx', ':id'), // Generated path: /blog/:id
|
|
150
|
+
$('blog/$.tsx', '*'), // Wildcard route, matches all unmatched paths under /blog
|
|
151
151
|
]),
|
|
152
|
-
]
|
|
153
|
-
})
|
|
152
|
+
];
|
|
153
|
+
});
|
|
154
154
|
```
|
|
155
155
|
|
|
156
156
|
**Use cases**:
|
|
@@ -170,11 +170,11 @@ The `$` function has the same functionality as the `$.tsx` file in convention ro
|
|
|
170
170
|
export default defineRoutes(({ page }, fileRoutes) => {
|
|
171
171
|
return [
|
|
172
172
|
// Use page function to explicitly specify page route
|
|
173
|
-
page(
|
|
174
|
-
page(
|
|
175
|
-
page(
|
|
176
|
-
]
|
|
177
|
-
})
|
|
173
|
+
page('home.tsx', '/'),
|
|
174
|
+
page('about.tsx', 'about'),
|
|
175
|
+
page('contact.tsx', 'contact'),
|
|
176
|
+
];
|
|
177
|
+
});
|
|
178
178
|
```
|
|
179
179
|
|
|
180
180
|
### Routes Without Path
|
|
@@ -186,12 +186,12 @@ export default defineRoutes(({ layout, page }, fileRoutes) => {
|
|
|
186
186
|
return [
|
|
187
187
|
// Use layout function to explicitly specify layout route
|
|
188
188
|
// auth/layout.tsx needs to contain <Outlet> to render child routes
|
|
189
|
-
layout(
|
|
190
|
-
page(
|
|
191
|
-
page(
|
|
189
|
+
layout('auth/layout.tsx', [
|
|
190
|
+
page('login/page.tsx', 'login'),
|
|
191
|
+
page('register/page.tsx', 'register'),
|
|
192
192
|
]),
|
|
193
|
-
]
|
|
194
|
-
})
|
|
193
|
+
];
|
|
194
|
+
});
|
|
195
195
|
```
|
|
196
196
|
|
|
197
197
|
The above configuration will generate:
|
|
@@ -204,11 +204,11 @@ The above configuration will generate:
|
|
|
204
204
|
```ts
|
|
205
205
|
export default defineRoutes(({ page }, fileRoutes) => {
|
|
206
206
|
return [
|
|
207
|
-
page(
|
|
208
|
-
page(
|
|
209
|
-
page(
|
|
210
|
-
]
|
|
211
|
-
})
|
|
207
|
+
page('user.tsx', 'user'),
|
|
208
|
+
page('user.tsx', 'profile'),
|
|
209
|
+
page('user.tsx', 'account'),
|
|
210
|
+
];
|
|
211
|
+
});
|
|
212
212
|
```
|
|
213
213
|
|
|
214
214
|
### Dynamic Routes
|
|
@@ -219,12 +219,12 @@ Config routes support dynamic route parameters:
|
|
|
219
219
|
export default defineRoutes(({ page }, fileRoutes) => {
|
|
220
220
|
return [
|
|
221
221
|
// Required parameter
|
|
222
|
-
page(
|
|
222
|
+
page('blog/detail.tsx', 'blog/:id'),
|
|
223
223
|
|
|
224
224
|
// Optional parameter
|
|
225
|
-
page(
|
|
226
|
-
]
|
|
227
|
-
})
|
|
225
|
+
page('blog/index.tsx', 'blog/:slug?'),
|
|
226
|
+
];
|
|
227
|
+
});
|
|
228
228
|
```
|
|
229
229
|
|
|
230
230
|
## Automatic Route-Related File Discovery
|
|
@@ -235,10 +235,10 @@ Config routes automatically discover component-related files without manual conf
|
|
|
235
235
|
// modern.routes.ts
|
|
236
236
|
export default defineRoutes(({ route }, fileRoutes) => {
|
|
237
237
|
return [
|
|
238
|
-
route(
|
|
239
|
-
route(
|
|
240
|
-
]
|
|
241
|
-
})
|
|
238
|
+
route('pages/profile.tsx', 'profile'),
|
|
239
|
+
route('pages/user/detail.tsx', 'user/:id'),
|
|
240
|
+
];
|
|
241
|
+
});
|
|
242
242
|
```
|
|
243
243
|
|
|
244
244
|
Modern.js will automatically find and load:
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Routing
|
|
2
4
|
|
|
3
5
|
Modern.js routing is based on [React Router v7](https://reactrouter.com/en/main), offering file convention-based routing capabilities and supporting the industry-popular **nested routing** pattern. When an entry is recognized as [conventional routing](/guides/concept/entries.md#conventional-routing), Modern.js automatically generates the corresponding routing structure based on the file system.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Import JSON Files
|
|
2
4
|
|
|
3
5
|
Modern.js supports import JSON files in code by default. You can use Rsbuild plugins to support importing [YAML](https://yaml.org/) and [Toml](https://toml.io/en/) files and converting them to JSON format.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Playwright
|
|
2
4
|
|
|
3
5
|
Playwright is a testing framework that allows you to run tests automatically in Chromium, Firefox, and WebKit environments using a single API. You can use it to **write E2E tests**.
|
|
@@ -83,18 +85,18 @@ export default Index;
|
|
|
83
85
|
Next, add test cases to ensure the links on your pages work properly.
|
|
84
86
|
|
|
85
87
|
```ts title="tests/example.spec.ts"
|
|
86
|
-
import { test, expect } from '@playwright/test'
|
|
88
|
+
import { test, expect } from '@playwright/test';
|
|
87
89
|
|
|
88
90
|
test('should navigate to the about page', async ({ page }) => {
|
|
89
91
|
// Start from the index page (the baseURL is set via the webServer in the playwright.config.ts)
|
|
90
|
-
await page.goto('http://localhost:8080/')
|
|
92
|
+
await page.goto('http://localhost:8080/');
|
|
91
93
|
// Find an element with the text 'About' and click on it
|
|
92
|
-
await page.click('text=About')
|
|
94
|
+
await page.click('text=About');
|
|
93
95
|
// The new URL should be "/about" (baseURL is used there)
|
|
94
|
-
await expect(page).toHaveURL('http://localhost:8080/about')
|
|
96
|
+
await expect(page).toHaveURL('http://localhost:8080/about');
|
|
95
97
|
// The new page should contain an h1 with "About"
|
|
96
|
-
await expect(page.locator('h1')).toContainText('About')
|
|
97
|
-
})
|
|
98
|
+
await expect(page.locator('h1')).toContainText('About');
|
|
99
|
+
});
|
|
98
100
|
```
|
|
99
101
|
|
|
100
102
|
## Run Test Cases
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Rstest
|
|
2
4
|
|
|
3
5
|
[Rstest](https://rstest.rs) is a testing framework developed by the Rspack team and built on top of Rspack for fast test execution.
|
|
@@ -119,9 +121,9 @@ test('Page', async () => {
|
|
|
119
121
|
</Router>,
|
|
120
122
|
);
|
|
121
123
|
|
|
122
|
-
await expect
|
|
123
|
-
page.getByRole('heading', { level: 1, name: 'Home' })
|
|
124
|
-
|
|
124
|
+
await expect
|
|
125
|
+
.element(page.getByRole('heading', { level: 1, name: 'Home' }))
|
|
126
|
+
.toBeVisible();
|
|
125
127
|
});
|
|
126
128
|
```
|
|
127
129
|
|
|
@@ -231,8 +233,6 @@ For your Agent
|
|
|
231
233
|
|
|
232
234
|
Migrate to Rstest
|
|
233
235
|
|
|
234
|
-
Copy this prompt and send it to your coding agent.
|
|
235
|
-
|
|
236
236
|
Copy Prompt
|
|
237
237
|
|
|
238
238
|
Migrate this Modern.js project from Jest or Vitest to Rstest.
|
|
@@ -241,10 +241,12 @@ First install and use the migrate-to-rstest skill. If it is not installed, insta
|
|
|
241
241
|
npx skills add rstackjs/agent-skills --skill migrate-to-rstest
|
|
242
242
|
|
|
243
243
|
Follow the migrate-to-rstest skill instructions and the official Rstest migration guides:
|
|
244
|
+
|
|
244
245
|
- Jest: https://rstest.rs/guide/migration/jest
|
|
245
246
|
- Vitest: https://rstest.rs/guide/migration/vitest
|
|
246
247
|
|
|
247
248
|
Modern.js-specific requirement:
|
|
249
|
+
|
|
248
250
|
- Install and use @modern-js/adapter-rstest together with @rstest/core.
|
|
249
251
|
- Create or update rstest.config.ts to import withModernConfig from @modern-js/adapter-rstest.
|
|
250
252
|
- Reuse the Modern.js app configuration with extends: withModernConfig().
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Web Server
|
|
2
4
|
|
|
3
5
|
Modern.js provides an integrated Web server for applications that can run in any container environment with Node.js. Whether executing the `dev` command in a local development environment, running the `build && serve` commands in a production environment, or using the official deployment solution, it all runs through this Web server to host the application.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Modern.js For AI
|
|
2
4
|
|
|
3
5
|
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.
|
|
@@ -10,10 +12,10 @@ AI agents use them to get APIs, config, and conventions that exactly match your
|
|
|
10
12
|
|
|
11
13
|
## AGENTS.md
|
|
12
14
|
|
|
13
|
-
`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.
|
|
15
|
+
`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.
|
|
14
16
|
|
|
15
|
-
- **New projects**: `npx @modern-js/create` generates
|
|
16
|
-
- **Existing projects**: run `npx @modern-js/create --agents-md-only` at the project root to create or update
|
|
17
|
+
- **New projects**: `npx @modern-js/create` generates `AGENTS.md` by default; pass `--no-agents-md` to skip it.
|
|
18
|
+
- **Existing projects**: run `npx @modern-js/create --agents-md-only` at the project root to create or update `AGENTS.md`. Re-run it any time; your own additions are preserved.
|
|
17
19
|
|
|
18
20
|
Modern.js only maintains the content inside the `<!-- BEGIN:modernjs-agent-rules -->` markers in `AGENTS.md`; anything you write outside them is left untouched.
|
|
19
21
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Introduction to Modern.js
|
|
2
4
|
|
|
3
5
|
**Modern.js is a progressive web framework based on React**. At ByteDance, we use Modern.js to build upper-level frameworks that have supported the development of thousands of web applications.
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Quick Start
|
|
2
4
|
|
|
3
5
|
## Environment
|
|
4
6
|
|
|
5
7
|
### Node.js
|
|
6
8
|
|
|
7
|
-
Before getting started, you will need to install [Node.js](https://nodejs.org/), and ensure that your Node.js version is not lower than
|
|
9
|
+
Before getting started, you will need to install [Node.js](https://nodejs.org/), and ensure that your Node.js version is not lower than v22.18.0. **We recommend using the LTS version of Node.js 22.**
|
|
8
10
|
|
|
9
11
|
You can check the currently used Node.js version with the following command:
|
|
10
12
|
|
|
@@ -12,7 +14,7 @@ You can check the currently used Node.js version with the following command:
|
|
|
12
14
|
node -v
|
|
13
15
|
```
|
|
14
16
|
|
|
15
|
-
If you do not have Node.js installed in your current environment, or the installed version
|
|
17
|
+
If you do not have Node.js installed in your current environment, or the installed version does not meet this requirement, you can use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to install the required version.
|
|
16
18
|
|
|
17
19
|
Here is an example of how to install the Node.js 22 LTS version via nvm:
|
|
18
20
|
|
|
@@ -90,19 +92,18 @@ npx @modern-js/create@latest myapp
|
|
|
90
92
|
|
|
91
93
|
⚡ Start the development server:
|
|
92
94
|
|
|
93
|
-
pnpm
|
|
95
|
+
pnpm dev
|
|
94
96
|
```
|
|
95
97
|
|
|
96
98
|
Now, the project structure is as follows:
|
|
97
99
|
|
|
98
100
|
```
|
|
99
101
|
.
|
|
100
|
-
├── biome.json
|
|
101
102
|
├── modern.config.ts
|
|
102
103
|
├── package.json
|
|
103
104
|
├── README.md
|
|
105
|
+
├── rstack.config.mts
|
|
104
106
|
├── src
|
|
105
|
-
│ ├── modern-app-env.d.ts
|
|
106
107
|
│ ├── modern.runtime.ts
|
|
107
108
|
│ └── routes
|
|
108
109
|
│ ├── index.css
|
|
@@ -111,6 +112,13 @@ Now, the project structure is as follows:
|
|
|
111
112
|
└── tsconfig.json
|
|
112
113
|
```
|
|
113
114
|
|
|
115
|
+
New standalone projects use [Rstack CLI](https://rstack.rs/) for linting and formatting:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
pnpm check
|
|
119
|
+
pnpm format
|
|
120
|
+
```
|
|
121
|
+
|
|
114
122
|
## Development
|
|
115
123
|
|
|
116
124
|
Run `pnpm run dev` in the project to start the project:
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Application-Level Modules
|
|
2
4
|
|
|
3
5
|
Modern.js provides runtime APIs to quickly export application-level Module Federation modules from your application.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Deployment
|
|
2
4
|
|
|
3
5
|
In general, when deploying a Module Federation application, there are two key points to consider:
|
|
@@ -63,9 +65,9 @@ At this point, the `publicPath` defined in the producer's build output `mf-manif
|
|
|
63
65
|
"name": "remote",
|
|
64
66
|
"publicPath": "https://my-remote-module/"
|
|
65
67
|
},
|
|
66
|
-
"shared": [
|
|
68
|
+
"shared": [/* xxx */],
|
|
67
69
|
"remotes": [],
|
|
68
|
-
"exposes": [
|
|
70
|
+
"exposes": [/* xxx */]
|
|
69
71
|
}
|
|
70
72
|
```
|
|
71
73
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Integrating Internationalization
|
|
2
4
|
|
|
3
5
|
Modern.js provides the **@modern-js/plugin-i18n** plugin to support internationalization. When using Module Federation, you need to provide corresponding i18n integration solutions for different scenarios (components or applications).
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Introduction
|
|
2
4
|
|
|
3
5
|
Module Federation is an architectural pattern for dividing JavaScript applications, allowing you to share code and resources among multiple JavaScript applications.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Server-Side Rendering
|
|
2
4
|
|
|
3
5
|
`@module-federation/modern-js-v3` offers powerful capabilities, enabling developers to easily combine Module Federation with server-side rendering (SSR) in Modern.js applications.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Getting Started
|
|
2
4
|
|
|
3
5
|
To use Module Federation in Modern.js, we recommend using the official plugin `@module-federation/modern-js-v3`.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Configuration Changes
|
|
2
4
|
|
|
3
5
|
This document mainly introduces incompatible configuration changes and recommended migration methods when upgrading from Modern.js 2.0 to 3.0.
|
|
@@ -22,6 +24,18 @@ server: {
|
|
|
22
24
|
}
|
|
23
25
|
```
|
|
24
26
|
|
|
27
|
+
### dev.lazyCompilation
|
|
28
|
+
|
|
29
|
+
**Change**: The default value in development has changed. Pure CSR and streaming SSR applications enable lazy compilation by default with `{ imports: true, entries: false }`; applications using string SSR, RSC or SSG keep it disabled by default. This only affects development and does not change production build output.
|
|
30
|
+
|
|
31
|
+
**Migration Example**: To keep the 2.0 behavior, disable it explicitly:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
dev: {
|
|
35
|
+
lazyCompilation: false;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
25
39
|
## html
|
|
26
40
|
|
|
27
41
|
### html.appIcon
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Other Important Changes
|
|
2
4
|
|
|
3
5
|
This document introduces other important incompatible changes and related migration instructions when upgrading from Modern.js 2.0 to 3.0.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Tailwind Plugin Changes
|
|
2
4
|
|
|
3
5
|
Modern.js 3.0 recommends integrating Tailwind CSS through Rsbuild's native approach, no longer relying on the `@modern-js/plugin-tailwindcss` plugin, to fully utilize Rsbuild's more flexible configuration capabilities and better build experience.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Custom Web Server Changes
|
|
2
4
|
|
|
3
5
|
This chapter covers upgrades for two types of legacy custom Server APIs:
|
|
@@ -21,7 +23,10 @@ These two approaches are mutually exclusive in the legacy version. When migratin
|
|
|
21
23
|
|
|
22
24
|
```typescript
|
|
23
25
|
// Legacy - server/index.ts
|
|
24
|
-
export const unstableMiddleware: UnstableMiddleware[] = [
|
|
26
|
+
export const unstableMiddleware: UnstableMiddleware[] = [
|
|
27
|
+
middleware1,
|
|
28
|
+
middleware2,
|
|
29
|
+
];
|
|
25
30
|
|
|
26
31
|
// New - server/modern.server.ts
|
|
27
32
|
import { defineServerConfig } from '@modern-js/server-runtime';
|
|
@@ -38,13 +43,22 @@ export default defineServerConfig({
|
|
|
38
43
|
|
|
39
44
|
```typescript
|
|
40
45
|
// Legacy
|
|
41
|
-
import type {
|
|
42
|
-
|
|
46
|
+
import type {
|
|
47
|
+
UnstableMiddleware,
|
|
48
|
+
UnstableMiddlewareContext,
|
|
49
|
+
} from '@modern-js/server-runtime';
|
|
50
|
+
const middleware: UnstableMiddleware = async (
|
|
51
|
+
c: UnstableMiddlewareContext,
|
|
52
|
+
next,
|
|
53
|
+
) => {
|
|
43
54
|
return c.response.raw('response'); // Will continue rendering even without calling next
|
|
44
55
|
};
|
|
45
56
|
|
|
46
57
|
// New
|
|
47
|
-
import {
|
|
58
|
+
import {
|
|
59
|
+
defineServerConfig,
|
|
60
|
+
type MiddlewareHandler,
|
|
61
|
+
} from '@modern-js/server-runtime';
|
|
48
62
|
const middleware: MiddlewareHandler = async (c, next) => {
|
|
49
63
|
await next(); // Must call
|
|
50
64
|
return c.text('response');
|
|
@@ -88,7 +102,10 @@ export const afterRender = (ctx, next) => {
|
|
|
88
102
|
};
|
|
89
103
|
|
|
90
104
|
// New - server/modern.server.ts
|
|
91
|
-
import {
|
|
105
|
+
import {
|
|
106
|
+
defineServerConfig,
|
|
107
|
+
type MiddlewareHandler,
|
|
108
|
+
} from '@modern-js/server-runtime';
|
|
92
109
|
|
|
93
110
|
const renderMiddleware: MiddlewareHandler = async (c, next) => {
|
|
94
111
|
await next(); // Wait for page rendering first
|
|
@@ -104,6 +121,8 @@ const renderMiddleware: MiddlewareHandler = async (c, next) => {
|
|
|
104
121
|
};
|
|
105
122
|
|
|
106
123
|
export default defineServerConfig({
|
|
107
|
-
renderMiddlewares: [
|
|
124
|
+
renderMiddlewares: [
|
|
125
|
+
{ name: 'custom-content-injection', handler: renderMiddleware },
|
|
126
|
+
],
|
|
108
127
|
});
|
|
109
128
|
```
|