@modern-js/app-tools 3.9.2 → 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/commands/build.js +1 -2
- package/dist/cjs/commands/deploy.js +1 -3
- package/dist/cjs/commands/index.js +4 -0
- 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/index.js +15 -39
- package/dist/cjs/plugins/analyze/index.js +2 -2
- package/dist/cjs/plugins/analyze/utils.js +2 -3
- package/dist/cjs/plugins/initialize/index.js +3 -5
- package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.mjs +54 -2
- package/dist/esm/commands/build.mjs +1 -2
- package/dist/esm/commands/deploy.mjs +1 -3
- package/dist/esm/commands/index.mjs +4 -0
- 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/index.mjs +2 -10
- package/dist/esm/plugins/analyze/index.mjs +2 -2
- package/dist/esm/plugins/analyze/utils.mjs +2 -3
- package/dist/esm/plugins/initialize/index.mjs +3 -5
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.mjs +54 -2
- package/dist/esm-node/commands/build.mjs +1 -2
- package/dist/esm-node/commands/deploy.mjs +1 -3
- package/dist/esm-node/commands/index.mjs +4 -0
- 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/index.mjs +2 -10
- package/dist/esm-node/plugins/analyze/index.mjs +2 -2
- package/dist/esm-node/plugins/analyze/utils.mjs +2 -3
- package/dist/esm-node/plugins/initialize/index.mjs +3 -5
- package/dist/types/index.d.ts +1 -3
- package/dist/types/plugins/analyze/utils.d.ts +1 -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 +6 -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 +6 -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 +96 -19
- 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 +89 -18
- package/docs/configure/app/tools/style-loader.md +2 -0
- package/docs/configure/app/tools/svgr.md +91 -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 +31 -17
- 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 +8 -7
- package/docs/plugin/cli-plugins/api.md +2 -0
- package/docs/plugin/cli-plugins/life-cycle.md +2 -0
- package/docs/plugin/introduction.md +12 -10
- 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 +18 -19
- 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
|
@@ -4,9 +4,25 @@ class HtmlAsyncChunkPlugin {
|
|
|
4
4
|
apply(compiler) {
|
|
5
5
|
compiler.hooks.compilation.tap(this.name, (compilation)=>{
|
|
6
6
|
const hooks = this.htmlPlugin.getCompilationHooks(compilation);
|
|
7
|
-
|
|
7
|
+
const runtimeInEntry = false === compiler.options.optimization.runtimeChunk;
|
|
8
|
+
const getEntryRuntimeUrls = (publicPath)=>new Set([
|
|
9
|
+
...compilation.entrypoints.values()
|
|
10
|
+
].flatMap((entrypoint)=>[
|
|
11
|
+
...entrypoint.getRuntimeChunk().files
|
|
12
|
+
].flatMap((file)=>{
|
|
13
|
+
const pathname = file.split('?', 1)[0];
|
|
14
|
+
return [
|
|
15
|
+
`${publicPath}${pathname}`,
|
|
16
|
+
`${publicPath}${pathname.split('/').map(encodeURIComponent).join('/')}`
|
|
17
|
+
];
|
|
18
|
+
})));
|
|
19
|
+
hooks.alterAssetTagGroups.tap({
|
|
20
|
+
name: this.name,
|
|
21
|
+
stage: -1
|
|
22
|
+
}, (assets)=>{
|
|
8
23
|
const headTags = [];
|
|
9
24
|
const bodyTags = [];
|
|
25
|
+
const entryRuntimeUrls = runtimeInEntry ? getEntryRuntimeUrls(assets.publicPath) : new Set();
|
|
10
26
|
const processScriptTag = (tag)=>{
|
|
11
27
|
const { attributes } = tag;
|
|
12
28
|
if (attributes && true === attributes.defer) {
|
|
@@ -14,7 +30,7 @@ class HtmlAsyncChunkPlugin {
|
|
|
14
30
|
delete attributes.defer;
|
|
15
31
|
}
|
|
16
32
|
const src = attributes?.src;
|
|
17
|
-
const isRuntimeChunk = src && RUNTIME_CHUNK_REGEX.test(src);
|
|
33
|
+
const isRuntimeChunk = 'string' == typeof src && (runtimeInEntry ? entryRuntimeUrls.has(src.split(/[?#]/, 1)[0]) : RUNTIME_CHUNK_REGEX.test(src));
|
|
18
34
|
return isRuntimeChunk ? bodyTags : headTags;
|
|
19
35
|
};
|
|
20
36
|
for (const tag of [
|
|
@@ -28,6 +44,42 @@ class HtmlAsyncChunkPlugin {
|
|
|
28
44
|
bodyTags
|
|
29
45
|
};
|
|
30
46
|
});
|
|
47
|
+
if (runtimeInEntry) hooks.alterAssetTagGroups.tap({
|
|
48
|
+
name: this.name,
|
|
49
|
+
stage: 1
|
|
50
|
+
}, (assets)=>{
|
|
51
|
+
const entryRuntimeUrls = getEntryRuntimeUrls(assets.publicPath);
|
|
52
|
+
for (const tag of assets.bodyTags){
|
|
53
|
+
const src = tag.attributes?.src;
|
|
54
|
+
if ("script" !== tag.tagName || 'string' != typeof src || !entryRuntimeUrls.has(src.split(/[?#]/, 1)[0])) continue;
|
|
55
|
+
const attributes = {
|
|
56
|
+
rel: 'module' === tag.attributes.type ? 'modulepreload' : 'preload',
|
|
57
|
+
href: src,
|
|
58
|
+
...'module' === tag.attributes.type ? {} : {
|
|
59
|
+
as: "script"
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const resourceAttributes = [
|
|
63
|
+
'crossorigin',
|
|
64
|
+
'integrity',
|
|
65
|
+
'referrerpolicy',
|
|
66
|
+
'fetchpriority',
|
|
67
|
+
'nonce'
|
|
68
|
+
];
|
|
69
|
+
for (const key of resourceAttributes)if (void 0 !== tag.attributes[key]) attributes[key] = tag.attributes[key];
|
|
70
|
+
if (!assets.headTags.some((existing)=>'link' === existing.tagName && [
|
|
71
|
+
'rel',
|
|
72
|
+
'href',
|
|
73
|
+
'as',
|
|
74
|
+
...resourceAttributes
|
|
75
|
+
].every((key)=>existing.attributes?.[key] === attributes[key]))) assets.headTags.push({
|
|
76
|
+
tagName: 'link',
|
|
77
|
+
voidTag: true,
|
|
78
|
+
attributes
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return assets;
|
|
82
|
+
});
|
|
31
83
|
});
|
|
32
84
|
}
|
|
33
85
|
constructor(htmlPlugin){
|
|
@@ -57,9 +57,8 @@ const build = async (api, options)=>{
|
|
|
57
57
|
logger.info('Starting production build...');
|
|
58
58
|
if (!appContext.builder) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
|
|
59
59
|
await appContext.builder.onAfterBuild(async ()=>copyEnvFiles(appContext.appDirectory, appContext.distDirectory));
|
|
60
|
-
|
|
60
|
+
await appContext.builder.build({
|
|
61
61
|
watch: options?.watch
|
|
62
62
|
});
|
|
63
|
-
if (!options?.watch) await buildResult?.close();
|
|
64
63
|
};
|
|
65
64
|
export { build };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { getServerPlugins } from "../utils/loadPlugins.mjs";
|
|
3
|
-
import { build } from "./build.mjs";
|
|
4
3
|
const deploy = async (api, options = {})=>{
|
|
5
4
|
const hooks = api.getHooks();
|
|
6
5
|
const { metaName } = api.getAppContext();
|
|
7
|
-
|
|
8
|
-
else await build(api);
|
|
6
|
+
await getServerPlugins(api, metaName);
|
|
9
7
|
await hooks.onBeforeDeploy.call(options);
|
|
10
8
|
await hooks.deploy.call();
|
|
11
9
|
await hooks.onAfterDeploy.call(options);
|
|
@@ -20,6 +20,10 @@ const serverCommand = (program, api)=>{
|
|
|
20
20
|
};
|
|
21
21
|
const deployCommand = (program, api)=>{
|
|
22
22
|
program.command('deploy').usage('[options]').option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-s --skip-build', i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options)=>{
|
|
23
|
+
if (!options.skipBuild) {
|
|
24
|
+
const { build } = await import("./build.mjs");
|
|
25
|
+
await build(api);
|
|
26
|
+
}
|
|
23
27
|
const { deploy } = await import("./deploy.mjs");
|
|
24
28
|
await deploy(api, options);
|
|
25
29
|
process.exit(0);
|
|
@@ -19,11 +19,6 @@ function getHookRunners(context) {
|
|
|
19
19
|
const result = await hooks?.appendEntryCode.call(params);
|
|
20
20
|
return result;
|
|
21
21
|
},
|
|
22
|
-
jestConfig: async (utils)=>{
|
|
23
|
-
const result = await hooks?.jestConfig.call(utils, (utils)=>utils);
|
|
24
|
-
return result;
|
|
25
|
-
},
|
|
26
|
-
afterTest: async ()=>hooks.afterTest.call(),
|
|
27
22
|
config: async ()=>hooks.config.call(),
|
|
28
23
|
resolvedConfig: (params)=>hooks.modifyResolvedConfig.call(params),
|
|
29
24
|
htmlPartials: async (params)=>{
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { createAsyncHook } from "@modern-js/plugin";
|
|
3
2
|
import { getHookRunners } from "./hooks.mjs";
|
|
4
3
|
const compatPlugin = ()=>({
|
|
5
4
|
name: '@modern-js/app-tools-compat',
|
|
@@ -16,10 +15,6 @@ const compatPlugin = ()=>({
|
|
|
16
15
|
useHookRunners: ()=>getHookRunners(getInternalContext())
|
|
17
16
|
};
|
|
18
17
|
},
|
|
19
|
-
registryHooks: {
|
|
20
|
-
jestConfig: createAsyncHook(),
|
|
21
|
-
afterTest: createAsyncHook()
|
|
22
|
-
},
|
|
23
18
|
setup: (api)=>{
|
|
24
19
|
api.updateAppContext({
|
|
25
20
|
toolsType: 'app-tools'
|
package/dist/esm-node/index.mjs
CHANGED
|
@@ -77,18 +77,12 @@ const appTools = ()=>({
|
|
|
77
77
|
].some((tag)=>getArgv().includes(tag));
|
|
78
78
|
if (isSkipBuild) return;
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
const shouldClean = [
|
|
80
|
+
if ([
|
|
82
81
|
'dev',
|
|
83
82
|
'start',
|
|
84
83
|
'build',
|
|
85
84
|
'deploy'
|
|
86
|
-
].includes(command)
|
|
87
|
-
'dev',
|
|
88
|
-
'start',
|
|
89
|
-
'build'
|
|
90
|
-
].includes(contextCommand);
|
|
91
|
-
if (shouldClean) {
|
|
85
|
+
].includes(command)) {
|
|
92
86
|
const resolvedConfig = api.getNormalizedConfig();
|
|
93
87
|
if (resolvedConfig.output.cleanDistPath) {
|
|
94
88
|
const appContext = api.getAppContext();
|
|
@@ -128,8 +122,6 @@ const appTools = ()=>({
|
|
|
128
122
|
});
|
|
129
123
|
const src = appTools;
|
|
130
124
|
export { defineConfig } from "./defineConfig.mjs";
|
|
131
|
-
export { build } from "./commands/build.mjs";
|
|
132
|
-
export { deploy } from "./commands/deploy.mjs";
|
|
133
125
|
export { dev } from "./commands/dev.mjs";
|
|
134
126
|
export { serve } from "./commands/serve.mjs";
|
|
135
127
|
export { closeServer } from "./utils/createServer.mjs";
|
|
@@ -24,7 +24,7 @@ const analyze = ()=>({
|
|
|
24
24
|
const resolvedConfig = api.getNormalizedConfig();
|
|
25
25
|
const hooks = api.getHooks();
|
|
26
26
|
try {
|
|
27
|
-
if (checkIsBuildCommands(
|
|
27
|
+
if (checkIsBuildCommands()) fs.emptydirSync(appContext.internalDirectory);
|
|
28
28
|
} catch {}
|
|
29
29
|
const apiOnly = await isApiOnly(appContext.appDirectory, resolvedConfig.source?.entriesDir, appContext.apiDirectory);
|
|
30
30
|
const [{ getProdServerRoutes }] = await Promise.all([
|
|
@@ -118,7 +118,7 @@ const analyze = ()=>({
|
|
|
118
118
|
htmlTemplates
|
|
119
119
|
};
|
|
120
120
|
api.updateAppContext(appContext);
|
|
121
|
-
if (checkIsBuildCommands(
|
|
121
|
+
if (checkIsBuildCommands()) {
|
|
122
122
|
await hooks.generateEntryCode.call({
|
|
123
123
|
entrypoints
|
|
124
124
|
});
|
|
@@ -53,7 +53,7 @@ const parseModule = async ({ source, filename })=>{
|
|
|
53
53
|
return await parse(content);
|
|
54
54
|
};
|
|
55
55
|
const getServerCombinedModuleFile = (internalDirectory, entryName)=>path.join(internalDirectory, entryName, 'server-loader-combined.js');
|
|
56
|
-
const checkIsBuildCommands = (
|
|
56
|
+
const checkIsBuildCommands = ()=>{
|
|
57
57
|
const buildCommands = [
|
|
58
58
|
'dev',
|
|
59
59
|
'start',
|
|
@@ -63,8 +63,7 @@ const checkIsBuildCommands = (contextCommand)=>{
|
|
|
63
63
|
'dev-worker'
|
|
64
64
|
];
|
|
65
65
|
const command = getCommand();
|
|
66
|
-
|
|
67
|
-
return 'dev' === contextCommand || 'start' === contextCommand || 'build' === contextCommand || 'deploy' === contextCommand;
|
|
66
|
+
return buildCommands.includes(command);
|
|
68
67
|
};
|
|
69
68
|
const checkIsServeCommand = ()=>{
|
|
70
69
|
const command = getCommand();
|
|
@@ -26,7 +26,7 @@ const initialize = ()=>({
|
|
|
26
26
|
api.modifyResolvedConfig(async (resolved)=>{
|
|
27
27
|
let appContext = api.getAppContext();
|
|
28
28
|
const userConfig = api.getConfig();
|
|
29
|
-
const port = await getServerPort(resolved
|
|
29
|
+
const port = await getServerPort(resolved);
|
|
30
30
|
appContext = {
|
|
31
31
|
...appContext,
|
|
32
32
|
port,
|
|
@@ -46,7 +46,6 @@ const initialize = ()=>({
|
|
|
46
46
|
'html',
|
|
47
47
|
'output',
|
|
48
48
|
'tools',
|
|
49
|
-
'testing',
|
|
50
49
|
'plugins',
|
|
51
50
|
'builderPlugins',
|
|
52
51
|
'deploy',
|
|
@@ -61,10 +60,9 @@ function stabilizeConfig(resolve, config, keys) {
|
|
|
61
60
|
resolve[key] = config[key] || {};
|
|
62
61
|
});
|
|
63
62
|
}
|
|
64
|
-
async function getServerPort(config
|
|
63
|
+
async function getServerPort(config) {
|
|
65
64
|
const prodPort = Number(process.env.PORT) || config.server.port || 8080;
|
|
66
|
-
|
|
67
|
-
if (isDev() && (isDevCommand() || isProgrammaticDev)) return getPort(Number(process.env.PORT) || prodPort);
|
|
65
|
+
if (isDev() && isDevCommand()) return getPort(Number(process.env.PORT) || prodPort);
|
|
68
66
|
return prodPort;
|
|
69
67
|
}
|
|
70
68
|
export default initialize;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,12 +3,10 @@ import { initAppContext } from './utils/initAppContext.js';
|
|
|
3
3
|
export * from './defineConfig.js';
|
|
4
4
|
export declare const appTools: () => CliPlugin<AppTools>;
|
|
5
5
|
export { defineConfig } from './defineConfig.js';
|
|
6
|
-
export { build } from './commands/build.js';
|
|
7
|
-
export { deploy } from './commands/deploy.js';
|
|
8
6
|
export { dev } from './commands/dev.js';
|
|
9
7
|
export { serve } from './commands/serve.js';
|
|
10
8
|
export { closeServer } from './utils/createServer.js';
|
|
11
|
-
export type {
|
|
9
|
+
export type { DeployOptions, DevOptions } from './utils/types.js';
|
|
12
10
|
export { generateWatchFiles } from './utils/generateWatchFiles.js';
|
|
13
11
|
export { resolveModernRsbuildConfig, type ResolveModernRsbuildConfigOptions, } from './rsbuild.js';
|
|
14
12
|
export * from './types/index.js';
|
|
@@ -5,6 +5,6 @@ export declare const parseModule: ({ source, filename, }: {
|
|
|
5
5
|
filename: string;
|
|
6
6
|
}) => Promise<readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean, hasModuleSyntax: boolean]>;
|
|
7
7
|
export declare const getServerCombinedModuleFile: (internalDirectory: string, entryName: string) => string;
|
|
8
|
-
export declare const checkIsBuildCommands: (
|
|
8
|
+
export declare const checkIsBuildCommands: () => boolean;
|
|
9
9
|
export declare const checkIsServeCommand: () => boolean;
|
|
10
10
|
export declare const isSubDirOrEqual: (parent: string, child: string) => boolean;
|
|
@@ -12,7 +12,6 @@ import type { PerformanceUserConfig } from './performance.js';
|
|
|
12
12
|
import type { ResolveUserConfig } from './resolve.js';
|
|
13
13
|
import type { SecurityUserConfig } from './security.js';
|
|
14
14
|
import type { SourceUserConfig } from './source.js';
|
|
15
|
-
import type { TestingUserConfig } from './testing.js';
|
|
16
15
|
import type { ToolsUserConfig } from './tools.js';
|
|
17
16
|
export * from './output.js';
|
|
18
17
|
export interface AppToolsUserConfig {
|
|
@@ -32,7 +31,6 @@ export interface AppToolsUserConfig {
|
|
|
32
31
|
html?: HtmlUserConfig;
|
|
33
32
|
tools?: ToolsUserConfig;
|
|
34
33
|
security?: SecurityUserConfig;
|
|
35
|
-
testing?: TestingUserConfig;
|
|
36
34
|
builderPlugins?: RsbuildPlugins;
|
|
37
35
|
performance?: PerformanceUserConfig;
|
|
38
36
|
environments?: RsbuildConfig['environments'];
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import type { BuilderConfig } from '@modern-js/builder';
|
|
2
|
-
import type { JestConfig } from '@modern-js/types';
|
|
3
2
|
import type { UnwrapBuilderConfig } from '../utils.js';
|
|
4
3
|
type BuilderToolsConfig = UnwrapBuilderConfig<BuilderConfig, 'tools'>;
|
|
5
4
|
export interface ToolsUserConfig extends Omit<BuilderToolsConfig, 'swc'> {
|
|
6
|
-
/**
|
|
7
|
-
* Used to custom Jest configurations.
|
|
8
|
-
* @requires `test` plugin.
|
|
9
|
-
* The configuration of `tools.jest` is provided by `test` plugin.
|
|
10
|
-
* Please use `yarn new` or `pnpm new` to enable the corresponding capability.
|
|
11
|
-
*/
|
|
12
|
-
jest?: JestConfig | ((jestConfig: JestConfig) => JestConfig);
|
|
13
5
|
/**
|
|
14
6
|
* Used to custom SWC configurations.
|
|
15
7
|
* @requires `swc` plugin.
|
|
@@ -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
|
# Commands
|
|
2
4
|
|
|
3
5
|
Modern.js has some built-in commands that can help you quickly start a development server, build production environment code, and more.
|
|
@@ -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
|
# lambda/\*.ts
|
|
2
4
|
|
|
3
5
|
After enabling BFF, the files under the `lambda/` directory will be registered as BFF routes according to conventions.
|
|
@@ -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
|
# Favicon
|
|
2
4
|
|
|
3
5
|
When there is a `favicon.*` file in the `config` directory at the root of the project, Modern.js will automatically set the file to the [html.favicon](/configure/app/html/favicon.md) configuration option for generating the favicon icon on the page:
|
|
@@ -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
|
# html/
|
|
2
4
|
|
|
3
5
|
You can inject custom HTML fragments at different locations of the default internal HTML template through the `config/html` directory.
|
|
@@ -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
|
# Apple Touch Icon
|
|
2
4
|
|
|
3
5
|
When there is an `icon.*` file in the `config` directory at the root of the project, Modern.js will automatically set the file to the [html.appIcon](/configure/app/html/app-icon.md) configuration option for generating the Apple Touch Icon icon under the iOS 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
|
# public/
|
|
2
4
|
|
|
3
5
|
Any static assets can be placed in the `public/` directory, and the files will be deployed to the corresponding application domain by the server.
|
|
@@ -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
|
# upload/
|
|
2
4
|
|
|
3
5
|
Any static assets can be placed in the `upload/` directory.
|
|
@@ -26,9 +28,7 @@ In React components, you can add this prefix through [Environment Variables](/gu
|
|
|
26
28
|
|
|
27
29
|
```tsx
|
|
28
30
|
export default () => {
|
|
29
|
-
return
|
|
30
|
-
<img src={`${process.env.ASSET_PREFIX}/upload/banner.png`}></img>
|
|
31
|
-
);
|
|
31
|
+
return <img src={`${process.env.ASSET_PREFIX}/upload/banner.png`}></img>;
|
|
32
32
|
};
|
|
33
33
|
```
|
|
34
34
|
|
|
@@ -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.config.ts
|
|
2
4
|
|
|
3
5
|
The Modern.js configuration file. Through this file, you can personalize the configuration of various aspects of the current 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
|
# modern.server.ts
|
|
2
4
|
|
|
3
5
|
This file extends the Modern.js Server. In this file, you can configure [Middleware](/guides/advanced-features/web-server.md#middleware), [RenderMiddleware](/guides/advanced-features/web-server.md#rendermiddleware), or [Plugin](/guides/advanced-features/web-server.md#plugin) for the Server that starts with the Modern.js 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
|
# shared/
|
|
2
4
|
|
|
3
5
|
Shared source code directory. When there is common code in `api/`, `server/`, and `src/` in the project, you can put these codes in the `shared` directory instead of directly referencing them.
|
|
@@ -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
|
# App.tsx
|
|
2
4
|
|
|
3
5
|
The entry identifier when using [Self-controlled Routing](/guides/concept/entries.md#self-controlled-routing) in 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
|
# entry.tsx
|
|
2
4
|
|
|
3
5
|
Normally, the [`routes/`](/apis/app/hooks/src/routes.md) and [`App.tsx`](/apis/app/hooks/src/app.md) hook files can meet our needs. When we need to add custom behavior before component rendering or take full control of the Rspack packaging entry, we can create `entry.ts` file in the src or entry directory. Here are two cases for discussion。
|
|
@@ -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
|
# entry.server.tsx
|
|
2
4
|
|
|
3
5
|
When the project initiates `server.ssr`, Modern.js generates a default Server-Side entry. The sample code is as follows:
|
|
@@ -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.runtime.ts
|
|
2
4
|
|
|
3
5
|
The Modern.js Runtime configuration file allows for personalized configuration of the Runtime capabilities for the current 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
|
# routes/
|
|
2
4
|
|
|
3
5
|
The identifier for the entry point when the application uses [Conventional Routing](/guides/basic-features/routes/routes.md#conventional-routing).
|
|
@@ -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|node].tsx
|
|
2
4
|
|
|
3
5
|
Used in the application project to place server-side code. When `*.tsx` and `*.[server|node].tsx` coexist, SSR will prefer to use the `*.[server|node].tsx` file instead of the `*.tsx` file when rendering on the server.
|
|
@@ -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
|
# createRoot
|
|
2
4
|
|
|
3
5
|
It is used to create the root component provided by Modern.js, which will automatically register Runtime plugins and complete the initialization of Runtime plugins.
|
|
@@ -11,7 +13,9 @@ import { createRoot } from '@modern-js/runtime/react';
|
|
|
11
13
|
## Function Signature
|
|
12
14
|
|
|
13
15
|
```ts
|
|
14
|
-
export function createRoot(
|
|
16
|
+
export function createRoot(
|
|
17
|
+
UserApp?: React.ComponentType | null,
|
|
18
|
+
): React.ComponentType<any>;
|
|
15
19
|
```
|
|
16
20
|
|
|
17
21
|
### Parameters
|
|
@@ -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
|
# render
|
|
2
4
|
|
|
3
5
|
It is used to render project components.
|
|
@@ -13,7 +15,10 @@ render(<ModernRoot />);
|
|
|
13
15
|
## Function Signature
|
|
14
16
|
|
|
15
17
|
```ts
|
|
16
|
-
export function render(
|
|
18
|
+
export function render(
|
|
19
|
+
App: React.ReactElement,
|
|
20
|
+
id?: HTMLElement | string,
|
|
21
|
+
): Promise<any>;
|
|
17
22
|
```
|
|
18
23
|
|
|
19
24
|
### Parameters
|
|
@@ -30,7 +35,7 @@ import { render } from '@modern-js/runtime/browser';
|
|
|
30
35
|
const ModernRoot = createRoot();
|
|
31
36
|
|
|
32
37
|
async function beforeRender() {
|
|
33
|
-
|
|
38
|
+
// todo
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
beforeRender().then(() => {
|
|
@@ -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
|
# RuntimeContext
|
|
2
4
|
|
|
3
5
|
`RuntimeContext` is a React Context used to get Runtime context information in components. This Context can be accessed through React's `use` or `useContext` API.
|
|
@@ -16,7 +18,7 @@ import { RuntimeContext } from '@modern-js/runtime';
|
|
|
16
18
|
|
|
17
19
|
export function App() {
|
|
18
20
|
const runtimeContext = use(RuntimeContext); // You can also use useContext(RuntimeContext)
|
|
19
|
-
return <div>Hello World</div
|
|
21
|
+
return <div>Hello World</div>;
|
|
20
22
|
}
|
|
21
23
|
```
|
|
22
24
|
|
|
@@ -50,21 +52,21 @@ type TRuntimeContext = {
|
|
|
50
52
|
```ts
|
|
51
53
|
type RequestContext = {
|
|
52
54
|
request: {
|
|
53
|
-
params: Record<string, string>;
|
|
54
|
-
pathname: string;
|
|
55
|
-
query: Record<string, string>;
|
|
56
|
-
headers: IncomingHttpHeaders;
|
|
57
|
-
host: string;
|
|
58
|
-
url: string;
|
|
59
|
-
referer?: string;
|
|
60
|
-
userAgent?: string;
|
|
61
|
-
cookie?: string;
|
|
62
|
-
cookieMap?: Record<string, string>;
|
|
55
|
+
params: Record<string, string>; // Route parameters
|
|
56
|
+
pathname: string; // Pathname
|
|
57
|
+
query: Record<string, string>; // Query parameters
|
|
58
|
+
headers: IncomingHttpHeaders; // Request headers
|
|
59
|
+
host: string; // Hostname
|
|
60
|
+
url: string; // Full URL
|
|
61
|
+
referer?: string; // Referrer page
|
|
62
|
+
userAgent?: string; // User agent
|
|
63
|
+
cookie?: string; // Cookie string
|
|
64
|
+
cookieMap?: Record<string, string>; // Cookie map object
|
|
63
65
|
};
|
|
64
66
|
response: {
|
|
65
|
-
setHeader: (key: string, value: string) => void;
|
|
66
|
-
status: (code: number) => void;
|
|
67
|
-
locals: Record<string, any>;
|
|
67
|
+
setHeader: (key: string, value: string) => void; // Set response header (server-side only)
|
|
68
|
+
status: (code: number) => void; // Set status code (server-side only)
|
|
69
|
+
locals: Record<string, any>; // Local data
|
|
68
70
|
};
|
|
69
71
|
};
|
|
70
72
|
```
|
|
@@ -88,11 +90,11 @@ function App() {
|
|
|
88
90
|
|
|
89
91
|
if (isBrowser === true) {
|
|
90
92
|
// Browser-side execution logic
|
|
91
|
-
console.log('browser render')
|
|
93
|
+
console.log('browser render');
|
|
92
94
|
} else {
|
|
93
95
|
// Server-side execution logic
|
|
94
96
|
// Note: Functions like logger need to be injected into context through Runtime plugins
|
|
95
|
-
console.log('server render')
|
|
97
|
+
console.log('server render');
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
100
|
```
|
|
@@ -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
|
# router
|
|
2
4
|
|
|
3
5
|
:::info
|
|
@@ -131,8 +133,10 @@ export default ErrorBoundary;
|
|
|
131
133
|
```ts
|
|
132
134
|
declare function Link(props: LinkProps): React.ReactElement;
|
|
133
135
|
|
|
134
|
-
interface LinkProps
|
|
135
|
-
|
|
136
|
+
interface LinkProps extends Omit<
|
|
137
|
+
React.AnchorHTMLAttributes<HTMLAnchorElement>,
|
|
138
|
+
'href'
|
|
139
|
+
> {
|
|
136
140
|
replace?: boolean;
|
|
137
141
|
state?: any;
|
|
138
142
|
to: To;
|
|
@@ -153,12 +157,13 @@ A `<Link>` is an element that lets the user navigate to another page by clicking
|
|
|
153
157
|
```ts
|
|
154
158
|
declare function NavLink(props: NavLinkProps): React.ReactElement;
|
|
155
159
|
|
|
156
|
-
interface NavLinkProps
|
|
157
|
-
|
|
160
|
+
interface NavLinkProps extends Omit<
|
|
161
|
+
LinkProps,
|
|
162
|
+
'className' | 'style' | 'children'
|
|
163
|
+
> {
|
|
158
164
|
caseSensitive?: boolean;
|
|
159
165
|
children?:
|
|
160
|
-
| React.ReactNode
|
|
161
|
-
| ((props: { isActive: boolean }) => React.ReactNode);
|
|
166
|
+
React.ReactNode | ((props: { isActive: boolean }) => React.ReactNode);
|
|
162
167
|
className?: string | ((props: { isActive: boolean }) => string | undefined);
|
|
163
168
|
end?: boolean;
|
|
164
169
|
style?:
|
|
@@ -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
|
# NoSSR
|
|
2
4
|
|
|
3
5
|
The content wrapped by NoSSR will not be rendered at the server, nor will it be rendered during the client side hydrate. it will only be rendered immediately after the entire app is rendered.
|
|
@@ -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
|
# renderStreaming
|
|
2
4
|
|
|
3
5
|
Used for `React v18` + `Streaming SSR` to render readable streams, used in conjunction with `createRequestHandler`.
|