@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.98 → 3.8.1-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/bin/modern-bundle-docs.js +7 -0
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +5 -1
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +80 -11
- package/dist/cjs/bundleDocs.js +114 -0
- package/dist/cjs/commands/build.js +2 -1
- package/dist/cjs/commands/deploy.js +4 -2
- package/dist/cjs/commands/index.js +0 -4
- package/dist/cjs/config/default.js +2 -0
- package/dist/cjs/index.js +56 -15
- package/dist/cjs/plugins/analyze/index.js +2 -2
- package/dist/cjs/plugins/analyze/utils.js +3 -2
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.js +94 -18
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +1 -0
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +14 -0
- package/dist/cjs/plugins/initialize/index.js +4 -3
- package/dist/cjs/plugins/serverBuild.js +3 -2
- package/dist/cjs/ultramodern-release-envelope/framework-output.js +109 -57
- package/dist/esm/builder/generator/createBuilderProviderConfig.mjs +5 -1
- package/dist/esm/builder/generator/getBuilderEnvironments.mjs +70 -10
- package/dist/esm/bundleDocs.mjs +62 -0
- package/dist/esm/commands/build.mjs +2 -1
- package/dist/esm/commands/deploy.mjs +4 -2
- package/dist/esm/commands/index.mjs +0 -4
- package/dist/esm/config/default.mjs +2 -0
- package/dist/esm/index.mjs +15 -1
- package/dist/esm/plugins/analyze/index.mjs +2 -2
- package/dist/esm/plugins/analyze/utils.mjs +3 -2
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +1 -1
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +93 -18
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +1 -0
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +14 -0
- package/dist/esm/plugins/initialize/index.mjs +4 -3
- package/dist/esm/plugins/serverBuild.mjs +3 -2
- package/dist/esm/ultramodern-release-envelope/framework-output.mjs +107 -58
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.mjs +5 -1
- package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +70 -10
- package/dist/esm-node/bundleDocs.mjs +63 -0
- package/dist/esm-node/commands/build.mjs +2 -1
- package/dist/esm-node/commands/deploy.mjs +4 -2
- package/dist/esm-node/commands/index.mjs +0 -4
- package/dist/esm-node/config/default.mjs +2 -0
- package/dist/esm-node/index.mjs +15 -1
- package/dist/esm-node/plugins/analyze/index.mjs +2 -2
- package/dist/esm-node/plugins/analyze/utils.mjs +3 -2
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +1 -1
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +93 -18
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +1 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +14 -0
- package/dist/esm-node/plugins/initialize/index.mjs +4 -3
- package/dist/esm-node/plugins/serverBuild.mjs +3 -2
- package/dist/esm-node/ultramodern-release-envelope/framework-output.mjs +107 -58
- package/dist/types/builder/generator/getBuilderEnvironments.d.ts +29 -0
- package/dist/types/bundleDocs.d.ts +20 -0
- package/dist/types/commands/deploy.d.ts +2 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/plugins/analyze/utils.d.ts +1 -1
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.d.ts +1 -1
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.d.mts +1 -1
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-worker-mf-ssr-runtime-plugin.d.mts +13 -0
- package/dist/types/types/config/dev.d.ts +6 -0
- package/dist/types/ultramodern-release-envelope/framework-output.d.ts +1 -0
- package/docs/apis/app/commands.md +231 -0
- package/docs/apis/app/hooks/api/lambda.md +9 -0
- package/docs/apis/app/hooks/config/favicon.md +24 -0
- package/docs/apis/app/hooks/config/html.md +5 -0
- package/docs/apis/app/hooks/config/icon.md +24 -0
- package/docs/apis/app/hooks/config/mock.md +6 -0
- package/docs/apis/app/hooks/config/public.md +26 -0
- package/docs/apis/app/hooks/config/upload.md +50 -0
- package/docs/apis/app/hooks/modern-config.md +5 -0
- package/docs/apis/app/hooks/server/server.md +5 -0
- package/docs/apis/app/hooks/shared.md +3 -0
- package/docs/apis/app/hooks/src/app.md +30 -0
- package/docs/apis/app/hooks/src/entry.md +34 -0
- package/docs/apis/app/hooks/src/entry.server.md +51 -0
- package/docs/apis/app/hooks/src/modern.runtime.md +5 -0
- package/docs/apis/app/hooks/src/routes.md +86 -0
- package/docs/apis/app/hooks/src/server.md +3 -0
- package/docs/apis/app/runtime/bff/use-backend-context.md +27 -0
- package/docs/apis/app/runtime/core/create-root.md +19 -0
- package/docs/apis/app/runtime/core/render.md +39 -0
- package/docs/apis/app/runtime/core/runtime-context.md +156 -0
- package/docs/apis/app/runtime/router/router.md +283 -0
- package/docs/apis/app/runtime/ssr/no-ssr.md +35 -0
- package/docs/apis/app/runtime/ssr/renderStreaming.md +67 -0
- package/docs/apis/app/runtime/ssr/renderString.md +60 -0
- package/docs/apis/app/runtime/ssr/requestHandler.md +44 -0
- package/docs/apis/app/runtime/utility/css-in-js.md +40 -0
- package/docs/apis/app/runtime/utility/head.md +35 -0
- package/docs/apis/app/runtime/utility/loadable.md +82 -0
- package/docs/community/blog/2022-0708-updates.md +91 -0
- package/docs/community/blog/2022-0910-updates.md +76 -0
- package/docs/community/blog/overview.md +63 -0
- package/docs/community/blog/v2-release-note.md +238 -0
- package/docs/community/blog/v3-release-note.md +622 -0
- package/docs/community/contributing-guide.md +252 -0
- package/docs/community/releases.md +23 -0
- package/docs/community/showcase.md +24 -0
- package/docs/community/team.md +14 -0
- package/docs/configure/app/bff/cross-project.md +20 -0
- package/docs/configure/app/bff/effect.md +313 -0
- package/docs/configure/app/bff/prefix.md +29 -0
- package/docs/configure/app/bff/runtime-framework.md +26 -0
- package/docs/configure/app/builder-plugins.md +66 -0
- package/docs/configure/app/dev/asset-prefix.md +13 -0
- package/docs/configure/app/dev/before-start-url.md +17 -0
- package/docs/configure/app/dev/client.md +41 -0
- package/docs/configure/app/dev/hmr.md +10 -0
- package/docs/configure/app/dev/host.md +18 -0
- package/docs/configure/app/dev/https.md +77 -0
- package/docs/configure/app/dev/lazy-compilation.md +39 -0
- package/docs/configure/app/dev/live-reload.md +10 -0
- package/docs/configure/app/dev/mock-dir.md +31 -0
- package/docs/configure/app/dev/progress-bar.md +19 -0
- package/docs/configure/app/dev/server.md +124 -0
- package/docs/configure/app/dev/setup-middlewares.md +32 -0
- package/docs/configure/app/dev/start-url.md +48 -0
- package/docs/configure/app/dev/watch-files.md +27 -0
- package/docs/configure/app/dev/write-to-disk.md +10 -0
- package/docs/configure/app/experiments/source-build.md +31 -0
- package/docs/configure/app/html/app-icon.md +28 -0
- package/docs/configure/app/html/crossorigin.md +10 -0
- package/docs/configure/app/html/favicon.md +16 -0
- package/docs/configure/app/html/inject.md +10 -0
- package/docs/configure/app/html/meta.md +24 -0
- package/docs/configure/app/html/mount-id.md +10 -0
- package/docs/configure/app/html/output-structure.md +10 -0
- package/docs/configure/app/html/script-loading.md +10 -0
- package/docs/configure/app/html/tags.md +15 -0
- package/docs/configure/app/html/template-parameters.md +33 -0
- package/docs/configure/app/html/template.md +10 -0
- package/docs/configure/app/html/title.md +18 -0
- package/docs/configure/app/output/asset-prefix.md +11 -0
- package/docs/configure/app/output/assets-retry.md +77 -0
- package/docs/configure/app/output/charset.md +10 -0
- package/docs/configure/app/output/clean-dist-path.md +16 -0
- package/docs/configure/app/output/convert-to-rem.md +79 -0
- package/docs/configure/app/output/copy.md +10 -0
- package/docs/configure/app/output/css-modules.md +48 -0
- package/docs/configure/app/output/data-uri-limit.md +26 -0
- package/docs/configure/app/output/disable-css-module-extension.md +55 -0
- package/docs/configure/app/output/disable-inline-runtime-chunk.md +41 -0
- package/docs/configure/app/output/disable-svgr.md +18 -0
- package/docs/configure/app/output/disable-ts-checker.md +49 -0
- package/docs/configure/app/output/dist-path.md +43 -0
- package/docs/configure/app/output/enable-asset-manifest.md +36 -0
- package/docs/configure/app/output/enable-css-module-tsdeclaration.md +28 -0
- package/docs/configure/app/output/enable-inline-route-manifests.md +16 -0
- package/docs/configure/app/output/externals.md +20 -0
- package/docs/configure/app/output/filename-hash.md +10 -0
- package/docs/configure/app/output/filename.md +55 -0
- package/docs/configure/app/output/inject-styles.md +10 -0
- package/docs/configure/app/output/inline-scripts.md +29 -0
- package/docs/configure/app/output/inline-styles.md +29 -0
- package/docs/configure/app/output/legal-comments.md +18 -0
- package/docs/configure/app/output/minify.md +22 -0
- package/docs/configure/app/output/override-browserslist.md +22 -0
- package/docs/configure/app/output/polyfill.md +12 -0
- package/docs/configure/app/output/source-map.md +30 -0
- package/docs/configure/app/output/split-route-chunks.md +16 -0
- package/docs/configure/app/output/ssg.md +81 -0
- package/docs/configure/app/output/ssgByEntries.md +90 -0
- package/docs/configure/app/output/svg-default-export.md +30 -0
- package/docs/configure/app/output/temp-dir.md +20 -0
- package/docs/configure/app/performance/build-cache.md +44 -0
- package/docs/configure/app/performance/chunk-split.md +40 -0
- package/docs/configure/app/performance/dns-prefetch.md +15 -0
- package/docs/configure/app/performance/preconnect.md +16 -0
- package/docs/configure/app/performance/prefetch.md +21 -0
- package/docs/configure/app/performance/preload.md +23 -0
- package/docs/configure/app/performance/print-file-size.md +40 -0
- package/docs/configure/app/performance/profile.md +10 -0
- package/docs/configure/app/performance/remove-console.md +10 -0
- package/docs/configure/app/performance/remove-moment-locale.md +10 -0
- package/docs/configure/app/performance/rsdoctor.md +38 -0
- package/docs/configure/app/plugins.md +59 -0
- package/docs/configure/app/resolve/alias-strategy.md +10 -0
- package/docs/configure/app/resolve/alias.md +9 -0
- package/docs/configure/app/resolve/condition-names.md +13 -0
- package/docs/configure/app/resolve/dedupe.md +9 -0
- package/docs/configure/app/resolve/extensions.md +13 -0
- package/docs/configure/app/runtime/0-intro.md +58 -0
- package/docs/configure/app/runtime/plugins.md +58 -0
- package/docs/configure/app/runtime/router.md +35 -0
- package/docs/configure/app/security/check-syntax.md +69 -0
- package/docs/configure/app/security/nonce.md +15 -0
- package/docs/configure/app/security/sri.md +20 -0
- package/docs/configure/app/server/base-url.md +26 -0
- package/docs/configure/app/server/port.md +18 -0
- package/docs/configure/app/server/public-routes.md +22 -0
- package/docs/configure/app/server/routes.md +86 -0
- package/docs/configure/app/server/rsc.md +22 -0
- package/docs/configure/app/server/ssr-by-entries.md +25 -0
- package/docs/configure/app/server/ssr.md +80 -0
- package/docs/configure/app/server/tsconfig-path.md +59 -0
- package/docs/configure/app/source/alias-strategy.md +14 -0
- package/docs/configure/app/source/alias.md +23 -0
- package/docs/configure/app/source/config-dir.md +20 -0
- package/docs/configure/app/source/decorators.md +25 -0
- package/docs/configure/app/source/define.md +16 -0
- package/docs/configure/app/source/disable-default-entries.md +28 -0
- package/docs/configure/app/source/enable-async-entry.md +54 -0
- package/docs/configure/app/source/enable-async-pre-entry.md +26 -0
- package/docs/configure/app/source/entries-dir.md +35 -0
- package/docs/configure/app/source/entries.md +179 -0
- package/docs/configure/app/source/exclude.md +10 -0
- package/docs/configure/app/source/global-vars.md +106 -0
- package/docs/configure/app/source/include.md +36 -0
- package/docs/configure/app/source/main-entry-name.md +24 -0
- package/docs/configure/app/source/pre-entry.md +10 -0
- package/docs/configure/app/source/react-compiler.md +68 -0
- package/docs/configure/app/source/transform-import.md +27 -0
- package/docs/configure/app/split-chunks.md +17 -0
- package/docs/configure/app/tools/autoprefixer.md +44 -0
- package/docs/configure/app/tools/bundler-chain.md +26 -0
- package/docs/configure/app/tools/css-extract.md +33 -0
- package/docs/configure/app/tools/css-loader.md +17 -0
- package/docs/configure/app/tools/dev-server.md +113 -0
- package/docs/configure/app/tools/html-plugin.md +41 -0
- package/docs/configure/app/tools/less.md +81 -0
- package/docs/configure/app/tools/lightningcss-loader.md +35 -0
- package/docs/configure/app/tools/minify-css.md +53 -0
- package/docs/configure/app/tools/postcss.md +34 -0
- package/docs/configure/app/tools/rspack.md +10 -0
- package/docs/configure/app/tools/sass.md +78 -0
- package/docs/configure/app/tools/style-loader.md +10 -0
- package/docs/configure/app/tools/swc.md +65 -0
- package/docs/configure/app/tools/ts-checker.md +116 -0
- package/docs/configure/app/usage.md +276 -0
- package/docs/guides/advanced-features/bff/cross-project.md +109 -0
- package/docs/guides/advanced-features/bff/data-platform.md +116 -0
- package/docs/guides/advanced-features/bff/extend-server.md +120 -0
- package/docs/guides/advanced-features/bff/frameworks.md +243 -0
- package/docs/guides/advanced-features/bff/function.md +318 -0
- package/docs/guides/advanced-features/bff/operators.md +554 -0
- package/docs/guides/advanced-features/bff/sdk.md +116 -0
- package/docs/guides/advanced-features/bff/upload.md +101 -0
- package/docs/guides/advanced-features/bff.md +18 -0
- package/docs/guides/advanced-features/build-performance.md +130 -0
- package/docs/guides/advanced-features/compatibility.md +120 -0
- package/docs/guides/advanced-features/international/advanced.md +128 -0
- package/docs/guides/advanced-features/international/api.md +267 -0
- package/docs/guides/advanced-features/international/best-practices.md +286 -0
- package/docs/guides/advanced-features/international/configuration.md +228 -0
- package/docs/guides/advanced-features/international/locale-detection.md +126 -0
- package/docs/guides/advanced-features/international/quick-start.md +128 -0
- package/docs/guides/advanced-features/international/resource-loading.md +154 -0
- package/docs/guides/advanced-features/international/routing.md +173 -0
- package/docs/guides/advanced-features/international.md +27 -0
- package/docs/guides/advanced-features/low-level.md +46 -0
- package/docs/guides/advanced-features/page-performance/code-split.md +77 -0
- package/docs/guides/advanced-features/page-performance/inline-assets.md +159 -0
- package/docs/guides/advanced-features/page-performance/optimize-bundle.md +97 -0
- package/docs/guides/advanced-features/page-performance/react-compiler.md +51 -0
- package/docs/guides/advanced-features/server-monitor/logger.md +41 -0
- package/docs/guides/advanced-features/server-monitor/metrics.md +58 -0
- package/docs/guides/advanced-features/server-monitor/monitors.md +242 -0
- package/docs/guides/advanced-features/source-build.md +164 -0
- package/docs/guides/advanced-features/web-server.md +288 -0
- package/docs/guides/basic-features/alias.md +102 -0
- package/docs/guides/basic-features/css/css-in-js.md +72 -0
- package/docs/guides/basic-features/css/css-modules.md +212 -0
- package/docs/guides/basic-features/css/css.md +27 -0
- package/docs/guides/basic-features/css/tailwindcss.md +27 -0
- package/docs/guides/basic-features/data/data-cache.md +510 -0
- package/docs/guides/basic-features/data/data-fetch.md +415 -0
- package/docs/guides/basic-features/data/data-write.md +227 -0
- package/docs/guides/basic-features/debug/mock.md +109 -0
- package/docs/guides/basic-features/debug/proxy.md +21 -0
- package/docs/guides/basic-features/debug/rsdoctor.md +47 -0
- package/docs/guides/basic-features/debug/using-storybook.md +112 -0
- package/docs/guides/basic-features/deploy.md +458 -0
- package/docs/guides/basic-features/env-vars.md +177 -0
- package/docs/guides/basic-features/html.md +255 -0
- package/docs/guides/basic-features/output-files.md +141 -0
- package/docs/guides/basic-features/render/before-render.md +108 -0
- package/docs/guides/basic-features/render/overview.md +47 -0
- package/docs/guides/basic-features/render/rsc.md +516 -0
- package/docs/guides/basic-features/render/ssg.md +228 -0
- package/docs/guides/basic-features/render/ssr-cache.md +201 -0
- package/docs/guides/basic-features/render/ssr.md +321 -0
- package/docs/guides/basic-features/render/streaming-ssr.md +264 -0
- package/docs/guides/basic-features/routes/config-routes.md +426 -0
- package/docs/guides/basic-features/routes/routes.md +524 -0
- package/docs/guides/basic-features/static-assets/json-files.md +120 -0
- package/docs/guides/basic-features/static-assets/svg-assets.md +168 -0
- package/docs/guides/basic-features/static-assets/wasm-assets.md +62 -0
- package/docs/guides/basic-features/static-assets.md +160 -0
- package/docs/guides/basic-features/testing/playwright.md +120 -0
- package/docs/guides/basic-features/testing/rstest.md +251 -0
- package/docs/guides/concept/builder.md +37 -0
- package/docs/guides/concept/entries.md +319 -0
- package/docs/guides/concept/server.md +35 -0
- package/docs/guides/get-started/ai-coding-agents.md +58 -0
- package/docs/guides/get-started/glossary.md +63 -0
- package/docs/guides/get-started/introduction.md +40 -0
- package/docs/guides/get-started/quick-start.md +269 -0
- package/docs/guides/get-started/tech-stack.md +91 -0
- package/docs/guides/get-started/ultramodern.md +440 -0
- package/docs/guides/get-started/upgrade.md +118 -0
- package/docs/guides/topic-detail/module-federation/application.md +116 -0
- package/docs/guides/topic-detail/module-federation/deploy.md +104 -0
- package/docs/guides/topic-detail/module-federation/i18n.md +670 -0
- package/docs/guides/topic-detail/module-federation/introduce.md +35 -0
- package/docs/guides/topic-detail/module-federation/ssr.md +182 -0
- package/docs/guides/topic-detail/module-federation/usage.md +219 -0
- package/docs/guides/troubleshooting/builder.md +110 -0
- package/docs/guides/troubleshooting/cli.md +35 -0
- package/docs/guides/troubleshooting/dependencies.md +119 -0
- package/docs/guides/troubleshooting/hmr.md +144 -0
- package/docs/guides/upgrade/config.md +954 -0
- package/docs/guides/upgrade/entry.md +463 -0
- package/docs/guides/upgrade/other.md +183 -0
- package/docs/guides/upgrade/overview.md +33 -0
- package/docs/guides/upgrade/tailwindcss.md +91 -0
- package/docs/guides/upgrade/web-server.md +109 -0
- package/docs/index.md +33 -0
- package/docs/llms.txt +290 -0
- package/docs/plugin/cli-plugins/api.md +573 -0
- package/docs/plugin/cli-plugins/life-cycle.md +2 -0
- package/docs/plugin/introduction.md +152 -0
- package/docs/plugin/official/cli-plugins/plugin-bff.md +5 -0
- package/docs/plugin/official/cli-plugins/plugin-ssg.md +5 -0
- package/docs/plugin/official/cli-plugins/plugin-styled-components.md +5 -0
- package/docs/plugin/official/cli-plugins.md +4 -0
- package/docs/plugin/plugin-system.md +238 -0
- package/docs/plugin/runtime-plugins/api.md +194 -0
- package/docs/plugin/runtime-plugins/life-cycle.md +2 -0
- package/docs/plugin/server-plugins/api.md +209 -0
- package/docs/plugin/server-plugins/life-cycle.md +13 -0
- package/docs/tutorials/examples/csr-auth.md +9 -0
- package/docs/tutorials/foundations/introduction.md +16 -0
- package/package.json +63 -22
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# Commands
|
|
2
|
+
|
|
3
|
+
UltraModern.js has some built-in commands that can help you quickly start a development server, build production environment code, and more.
|
|
4
|
+
|
|
5
|
+
Through this chapter, you can learn about the built-in commands of UltraModern.js and how to use them.
|
|
6
|
+
|
|
7
|
+
## modern dev
|
|
8
|
+
|
|
9
|
+
The `modern dev` command is used to start a local development server and compile the source code in the development environment.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
Usage: modern dev [options]
|
|
13
|
+
|
|
14
|
+
Options:
|
|
15
|
+
-e --entry <entry> compiler by entry
|
|
16
|
+
-c --config <config> specify the configuration file, which can be a relative or absolute path
|
|
17
|
+
-h, --help show command help
|
|
18
|
+
--web-only only start web service
|
|
19
|
+
--api-only only start API service
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
After running `modern dev`, UltraModern.js will watch source file changes and apply hot module replacement.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
$ modern dev
|
|
26
|
+
|
|
27
|
+
info Starting dev server...
|
|
28
|
+
|
|
29
|
+
> Local: http://localhost:8080/
|
|
30
|
+
> Network: http://192.168.0.1:8080/
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Compile Partial Pages
|
|
34
|
+
|
|
35
|
+
In multi-page (MPA) projects, the `--entry` option can be added to specify one or more pages to compile. In this way, only part of the code in the project will be compiled, and the dev startup speed will be faster.
|
|
36
|
+
|
|
37
|
+
For example, execute `modern dev --entry`, the entry selector will be displayed in the command line interface:
|
|
38
|
+
|
|
39
|
+
```text
|
|
40
|
+
$ modern dev --entry
|
|
41
|
+
|
|
42
|
+
? Please select the entry that needs to be built
|
|
43
|
+
❯ ◯ foo
|
|
44
|
+
◯ bar
|
|
45
|
+
◯ baz
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
For example, if you select the `foo` entry, only the code related to the `foo` entry will be compiled, and the code of other pages will not be compiled.
|
|
49
|
+
|
|
50
|
+
### Specify the page by parameter
|
|
51
|
+
|
|
52
|
+
You can also specify the page name through parameters after `--entry`, and the names of multiple pages can be separated by commas.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Compile foo page
|
|
56
|
+
modern dev --entry foo
|
|
57
|
+
|
|
58
|
+
# Compile foo and bar pages
|
|
59
|
+
modern dev --entry foo,bar
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## modern start
|
|
63
|
+
|
|
64
|
+
`modern start` is an alias of `modern dev` command, the usage of the two are exactly the same.
|
|
65
|
+
|
|
66
|
+
## modern build
|
|
67
|
+
|
|
68
|
+
The `modern build` command will build production-ready artifacts in the `dist/` directory by default. You can specify the output directory by modifying the configuration [`output.distPath`](/configure/app/output/dist-path.md).
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
Usage: modern build [options]
|
|
72
|
+
|
|
73
|
+
Options:
|
|
74
|
+
-c --config <config> specify the configuration file, which can be a relative or absolute path
|
|
75
|
+
-h, --help show command help
|
|
76
|
+
-w --watch turn on watch mode, watch for changes and rebuild
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## modern runtime status
|
|
80
|
+
|
|
81
|
+
The `modern runtime status` command reads the runtime status endpoint and prints the response. It targets `http://127.0.0.1:8080/_modern/runtime/status` by default.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
Usage: modern runtime status [options]
|
|
85
|
+
|
|
86
|
+
Options:
|
|
87
|
+
--endpoint <endpoint> runtime status endpoint URL or path
|
|
88
|
+
--token <token> runtime status auth token
|
|
89
|
+
--token-env <name> environment variable name that stores runtime status auth token (default: "MODERN_RUNTIME_SIGNAL_TOKEN")
|
|
90
|
+
--header-name <name> auth header name (default: "x-modernjs-runtime-signal-token")
|
|
91
|
+
--timeout <ms> request timeout in milliseconds (default: "5000")
|
|
92
|
+
--json output as JSON format for machine reading
|
|
93
|
+
-h, --help display help for command
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
If `--endpoint` is a path, it is resolved against `http://127.0.0.1:8080`. If `--token` is omitted, the command reads the token from the environment variable named by `--token-env`.
|
|
97
|
+
|
|
98
|
+
By default, the command formats the response as readable key/value lines. Add `--json` to print the raw JSON payload.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
modern runtime status --json
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## modern runtime fallback-signal
|
|
105
|
+
|
|
106
|
+
The `modern runtime fallback-signal` command posts a runtime fallback signal to the canary contract-gate endpoint. It targets `http://127.0.0.1:8080/_modern/contract-gates/runtime-fallback` by default.
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
Usage: modern runtime fallback-signal [options]
|
|
110
|
+
|
|
111
|
+
Options:
|
|
112
|
+
--app <appName> remote app name
|
|
113
|
+
--endpoint <endpoint> runtime fallback signal endpoint URL or path
|
|
114
|
+
--reason <reason> fallback reason (default: "runtime_fallback")
|
|
115
|
+
--phase <phase> fallback phase (default: "load")
|
|
116
|
+
--entry <entry> remote entry URL
|
|
117
|
+
--runtime-digest <digest> runtime digest value
|
|
118
|
+
--metadata <json> metadata JSON object string
|
|
119
|
+
--token <token> runtime signal auth token
|
|
120
|
+
--token-env <name> environment variable name that stores runtime signal auth token (default: "MODERN_RUNTIME_SIGNAL_TOKEN")
|
|
121
|
+
--header-name <name> auth header name (default: "x-modernjs-runtime-signal-token")
|
|
122
|
+
--timeout <ms> request timeout in milliseconds (default: "5000")
|
|
123
|
+
--json output as JSON format for machine reading
|
|
124
|
+
-h, --help display help for command
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The request body always includes `appName`, `reason`, and `phase`. It includes `entry`, `runtimeDigest`, and `metadata` only when those options are provided. `--metadata` must be a JSON object string.
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
modern runtime fallback-signal --app crm-shell --reason remote_load_failed --phase load --json
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## modern serve
|
|
134
|
+
|
|
135
|
+
The `modern serve` command is used to start an UltraModern.js project in the production environment. It can also be used to preview the artifacts built for the production environment locally. Please note that you need to execute the [`build`](/apis/app/commands.md#modern-build) command beforehand to generate the corresponding artifacts.
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
Usage: modern serve [options]
|
|
139
|
+
|
|
140
|
+
Options:
|
|
141
|
+
-c --config <config> specify the configuration file, which can be a relative or absolute path
|
|
142
|
+
-h, --help show command help
|
|
143
|
+
--api-only only run API service
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
By default, the project will run in `localhost:8080`, you can modify the server port number with `server.port`:
|
|
147
|
+
|
|
148
|
+
```js
|
|
149
|
+
export default defineConfig({
|
|
150
|
+
server: {
|
|
151
|
+
port: 8081,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## modern inspect
|
|
157
|
+
|
|
158
|
+
The `modern inspect` command is used to view the UltraModern.js config, [Rsbuild config](https://v2.rsbuild.rs/config/index) and Rspack config of the project.
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
Usage: modern inspect [options]
|
|
162
|
+
|
|
163
|
+
Options:
|
|
164
|
+
--env <env> view the configuration in the target environment (default: "development")
|
|
165
|
+
--output <output> Specify the path to output in the dist (default: "./")
|
|
166
|
+
--verbose Show the full function in the result
|
|
167
|
+
-c --config <config> specify the configuration file, which can be a relative or absolute path
|
|
168
|
+
-h, --help show command help
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
After executing the command `npx modern inspect` in the project root directory, the following files will be generated in the `dist` directory of the project:
|
|
172
|
+
|
|
173
|
+
- `modern.js.config.mjs`:The Modern.js configuration currently used.
|
|
174
|
+
- `rsbuild.config.mjs`: The Rsbuild config to use at build time.
|
|
175
|
+
- `rspack.config.web.mjs`: The Rspack config used by to use at build time.
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
➜ npx modern inspect
|
|
179
|
+
|
|
180
|
+
Inspect config succeed, open following files to view the content:
|
|
181
|
+
|
|
182
|
+
- Rsbuild Config: /root/my-project/dist/rsbuild.config.mjs
|
|
183
|
+
- Rspack Config (web): /root/my-project/dist/rspack.config.web.mjs
|
|
184
|
+
- Modern.js Config: /root/my-project/dist/modern.js.config.mjs
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Configuration Env
|
|
188
|
+
|
|
189
|
+
By default, the inspect command will output the development configs, you can use the `--env production` option to output the production configs:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
modern inspect --env production
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Verbose content
|
|
196
|
+
|
|
197
|
+
By default, the inspect command will omit the function content in the config object, you can use the `--verbose` option to output the full content of the function:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
modern inspect --verbose
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### SSR Configuration
|
|
204
|
+
|
|
205
|
+
If the project has enabled SSR, an additional `rspack.config.node.mjs` file will be generated in the `dist/`, corresponding to the Rspack configuration at SSR build time.
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
➜ npx modern inspect
|
|
209
|
+
|
|
210
|
+
Inspect config succeed, open following files to view the content:
|
|
211
|
+
|
|
212
|
+
- Rsbuild Config: /root/my-project/dist/rsbuild.config.mjs
|
|
213
|
+
- Rspack Config (web): /root/my-project/dist/rspack.config.web.mjs
|
|
214
|
+
- Rspack Config (node): /root/my-project/dist/rspack.config.node.mjs
|
|
215
|
+
- Modern.js Config: /root/my-project/dist/modern.js.config.mjs
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## modern deploy
|
|
219
|
+
|
|
220
|
+
The `modern deploy` command is used to generate artifacts required for the deployment platform.
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
Usage: modern deploy [options]
|
|
224
|
+
|
|
225
|
+
Options:
|
|
226
|
+
-c --config <config> Specify configuration file path, either relative or absolute
|
|
227
|
+
-s --skip-build Skip the build stage
|
|
228
|
+
-h, --help Display command help
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
For more details, refer to [Deploy Application](/guides/basic-features/deploy.md).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# lambda/\*.ts
|
|
2
|
+
|
|
3
|
+
After enabling BFF, the files under the `lambda/` directory will be registered as BFF routes according to conventions.
|
|
4
|
+
|
|
5
|
+
:::note
|
|
6
|
+
The files can be written in `js` or `ts` languages, but they must use `esm` syntax to export functions.
|
|
7
|
+
:::
|
|
8
|
+
|
|
9
|
+
For detailed information, refer to [BFF API Routes](/guides/advanced-features/bff/function.md#api-routes).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Favicon
|
|
2
|
+
|
|
3
|
+
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:
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
./config
|
|
7
|
+
└── favicon.ico
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
After the build is completed, you can see the following tags automatically generated in HTML:
|
|
11
|
+
|
|
12
|
+
```html
|
|
13
|
+
<link rel="icon" href="/favicon.ico" />
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Order
|
|
17
|
+
|
|
18
|
+
When setting up the favicon, Modern.js looks for files in the following order:
|
|
19
|
+
|
|
20
|
+
- `favicon.png`
|
|
21
|
+
- `favicon.jpg`
|
|
22
|
+
- `favicon.jpeg`
|
|
23
|
+
- `favicon.svg`
|
|
24
|
+
- `favicon.ico`
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Apple Touch Icon
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
./config
|
|
7
|
+
└── icon.png
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
After the build is completed, you can see the following tags automatically generated in HTML:
|
|
11
|
+
|
|
12
|
+
```html
|
|
13
|
+
<link rel="apple-touch-icon" sizes="180x180" href="/static/image/icon.png" />
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Order
|
|
17
|
+
|
|
18
|
+
When setting up the app icon, Modern.js looks for files in the following order:
|
|
19
|
+
|
|
20
|
+
- `icon.png`
|
|
21
|
+
- `icon.jpg`
|
|
22
|
+
- `icon.jpeg`
|
|
23
|
+
- `icon.svg`
|
|
24
|
+
- `icon.ico`
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# public/
|
|
2
|
+
|
|
3
|
+
Any static assets can be placed in the `public/` directory, and the files will be deployed to the corresponding application domain by the server.
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
The file routing is based on the convention of the directory structure, where `public/` is the root directory corresponding to the root path of the Web application.
|
|
8
|
+
|
|
9
|
+
For example, the `config/public/sdk/index.js` file will be deployed under `${domain}/sdk/index.js` after deployment.
|
|
10
|
+
|
|
11
|
+
## Scenarios
|
|
12
|
+
|
|
13
|
+
For example, authentication files required by third-party systems such as `robots.txt` and `auth.xml`.
|
|
14
|
+
|
|
15
|
+
Or SDKs for other business parties (requiring unchanged routing), or HTML files without entry.
|
|
16
|
+
|
|
17
|
+
:::info
|
|
18
|
+
For static assets (such as SVG images) that need to be imported through import in the source code, it is recommended to manage them in the `src/assets` directory.
|
|
19
|
+
|
|
20
|
+
:::
|
|
21
|
+
|
|
22
|
+
## Code Compression
|
|
23
|
+
|
|
24
|
+
If the file in the directory is a `.js` file, it will be automatically compressed during production environment construction.
|
|
25
|
+
|
|
26
|
+
If the file ends with `.min.js`, it will not be compressed.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# upload/
|
|
2
|
+
|
|
3
|
+
Any static assets can be placed in the `upload/` directory.
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
In the development environment, the static assets in this directory will be hosted under the `/upload` path. After building the application, the files in this directory will be copied to the dist directory.
|
|
8
|
+
|
|
9
|
+
This file convention is mainly used for developers to use plugins to proactively upload static assets to the CDN.
|
|
10
|
+
|
|
11
|
+
## Scenarios
|
|
12
|
+
|
|
13
|
+
For example, SDKs for project use only, such as `google-analysis.js` (usually requires HTTP caching).
|
|
14
|
+
|
|
15
|
+
Pictures, font files, common CSS, etc.
|
|
16
|
+
|
|
17
|
+
## Code Compression
|
|
18
|
+
|
|
19
|
+
If the file in the directory is a `.js` file, it will be automatically compressed during production environment construction.
|
|
20
|
+
|
|
21
|
+
If the file ends with `.min.js`, it will not be compressed.
|
|
22
|
+
|
|
23
|
+
## More Usage
|
|
24
|
+
|
|
25
|
+
In React components, you can add this prefix through [Environment Variables](/guides/basic-features/env-vars.md#asset_prefix):
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
export default () => {
|
|
29
|
+
return (
|
|
30
|
+
<img src={`${process.env.ASSET_PREFIX}/upload/banner.png`}></img>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
In addition, whether it is in [Custom HTML](/guides/basic-features/html.md) or any HTML file under [`config/public/`](/apis/app/hooks/config/public.md), you can directly use HTML tags to reference resources in the `config/upload/` directory:
|
|
36
|
+
|
|
37
|
+
```html
|
|
38
|
+
<script src="/upload/index.js"></script>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If you set the [`dev.assetPrefix`](/configure/app/dev/asset-prefix.md) or [`output.assetPrefix`](/configure/app/output/asset-prefix.md) prefix, you can also use template syntax to add the prefix directly:
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<script src="<%=assetPrefix %>/upload/index.js"></script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
:::info
|
|
48
|
+
Modern.js does not support using files under `config/upload/` through URLs in `config/public/*.css` (such as background-image).
|
|
49
|
+
|
|
50
|
+
:::
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# modern.config.ts
|
|
2
|
+
|
|
3
|
+
The Modern.js configuration file. Through this file, you can personalize the configuration of various aspects of the current project.
|
|
4
|
+
|
|
5
|
+
To learn more about how to use the configuration, please refer to [Configuration Usage](/configure/app/usage.md).
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# modern.server.ts
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
You can intercept and handle requests and responses, perform authentication and role checks, preprocess requests, and handle exceptions, etc. You can also insert specific business logic into the built-in processing logic (including route matching, resource addressing, header injection, page rendering, and static web hosting).
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# App.tsx
|
|
2
|
+
|
|
3
|
+
The entry identifier when using [Self-controlled Routing](/guides/concept/entries.md#self-controlled-routing) in the application.
|
|
4
|
+
|
|
5
|
+
`App.tsx` is not the actual application entry; Modern.js will automatically generate the real entry file, which is roughly as follows:
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
// runtime-global-context
|
|
9
|
+
import { setGlobalContext } from '@modern-js/runtime/context';
|
|
10
|
+
import App from '@_modern_js_src/App';
|
|
11
|
+
|
|
12
|
+
setGlobalContext({
|
|
13
|
+
App,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// index.tsx
|
|
17
|
+
import './runtime-global-context';
|
|
18
|
+
import { createRoot } from '@modern-js/runtime/react';
|
|
19
|
+
import { render } from '@modern-js/runtime/browser';
|
|
20
|
+
|
|
21
|
+
const ModernRoot = createRoot();
|
|
22
|
+
|
|
23
|
+
render(<ModernRoot />, 'root');
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
When `createRoot` is executed, it will retrieve the registered Global App and generate the actual React component.
|
|
27
|
+
|
|
28
|
+
:::note
|
|
29
|
+
In scenarios with multiple entry points, each entry can have its own independent `App.tsx`. For more details, see [Entry Points](/guides/concept/entries.md).
|
|
30
|
+
:::
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# entry.tsx
|
|
2
|
+
|
|
3
|
+
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。
|
|
4
|
+
|
|
5
|
+
## Add custom behavior before Render
|
|
6
|
+
|
|
7
|
+
This is implemented in `src/entry.ts` as follows:
|
|
8
|
+
|
|
9
|
+
```js title=src/entry.tsx
|
|
10
|
+
import { createRoot } from '@modern-js/runtime/react';
|
|
11
|
+
import { render } from '@modern-js/runtime/browser';
|
|
12
|
+
|
|
13
|
+
const ModernRoot = createRoot();
|
|
14
|
+
|
|
15
|
+
async function beforeRender() {
|
|
16
|
+
// todo
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
beforeRender().then(() => {
|
|
20
|
+
render(<ModernRoot />);
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Take full control of the Rspack entry
|
|
25
|
+
|
|
26
|
+
When the project does not install the `@modern-js/runtime` dependency, `src/entry.tsx?` is the real Rspack packaging entry file, and you can directly organize the code like using create-react-app and other scaffolds:
|
|
27
|
+
|
|
28
|
+
```js title=src/entry.jsx
|
|
29
|
+
import React from 'react';
|
|
30
|
+
import ReactDOM from 'react-dom/client';
|
|
31
|
+
import App from './App';
|
|
32
|
+
|
|
33
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(<App />);
|
|
34
|
+
```
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# entry.server.tsx
|
|
2
|
+
|
|
3
|
+
When the project initiates `server.ssr`, Modern.js generates a default Server-Side entry. The sample code is as follows:
|
|
4
|
+
|
|
5
|
+
```tsx title="entry.server.tsx"
|
|
6
|
+
import {
|
|
7
|
+
renderString,
|
|
8
|
+
createRequestHandler,
|
|
9
|
+
type HandleRequest,
|
|
10
|
+
} from '@modern-js/runtime/ssr/server';
|
|
11
|
+
|
|
12
|
+
const handleRequest: HandleRequest = async (request, ServerRoot, options) => {
|
|
13
|
+
const body = await renderString(request, <ServerRoot />, options);
|
|
14
|
+
|
|
15
|
+
return new Response(body, {
|
|
16
|
+
headers: {
|
|
17
|
+
'content-type': 'text/html; charset=utf-8',
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default createRequestHandler(handleRequest);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Add Custom Entry Points
|
|
26
|
+
|
|
27
|
+
Users need to customize the Server-Side Rendering entry points, they can customize the server entry in `src/entry.server.ts` or `src/{entryName}/entry.server.ts`.
|
|
28
|
+
|
|
29
|
+
```tsx title="src/entry.server.tsx"
|
|
30
|
+
import {
|
|
31
|
+
renderString,
|
|
32
|
+
createRequestHandler,
|
|
33
|
+
type HandleRequest,
|
|
34
|
+
} from '@modern-js/runtime/ssr/server';
|
|
35
|
+
|
|
36
|
+
const handleRequest: HandleRequest = async (request, ServerRoot, options) => {
|
|
37
|
+
// do something before rendering
|
|
38
|
+
const body = await renderString(request, <ServerRoot />, options);
|
|
39
|
+
|
|
40
|
+
const newBody = body + '<div>Byte-Dance</div>';
|
|
41
|
+
|
|
42
|
+
return new Response(newBody, {
|
|
43
|
+
headers: {
|
|
44
|
+
'content-type': 'text/html; charset=UTF-8',
|
|
45
|
+
'x-custom-header': 'abc',
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default createRequestHandler(handleRequest);
|
|
51
|
+
```
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# modern.runtime.ts
|
|
2
|
+
|
|
3
|
+
The Modern.js Runtime configuration file allows for personalized configuration of the Runtime capabilities for the current project.
|
|
4
|
+
|
|
5
|
+
For specific usage of the configuration, please refer to [Runtime Configuration](/configure/app/runtime/0-intro.md).
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# routes/
|
|
2
|
+
|
|
3
|
+
The identifier for the entry point when the application uses [Conventional Routing](/guides/basic-features/routes/routes.md#conventional-routing).
|
|
4
|
+
|
|
5
|
+
Conventional routing uses `routes/` as the convention for the entry point and analyzes the files in the `src/routes` directory to obtain the client-side routing configuration.
|
|
6
|
+
|
|
7
|
+
Any `layout.tsx` and `page.tsx` under `src/routes` will be used as the application's routes:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
.
|
|
11
|
+
└── routes
|
|
12
|
+
├── layout.tsx # [!code highlight]
|
|
13
|
+
├── page.tsx # [!code highlight]
|
|
14
|
+
└── user
|
|
15
|
+
├── layout.tsx
|
|
16
|
+
└── page.tsx
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Basic Example
|
|
20
|
+
|
|
21
|
+
The directory name under `routes` will be used as the mapping of the route URL. `layout.tsx` is used as the layout component and `page.tsx` is used as the content component in the routing. They are the leaf nodes of the entire route. For example, the following directory structure:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
.
|
|
25
|
+
└── routes
|
|
26
|
+
├── page.tsx
|
|
27
|
+
└── user
|
|
28
|
+
└── page.tsx
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
will generate two routes:
|
|
32
|
+
|
|
33
|
+
- `/`
|
|
34
|
+
- `/user`
|
|
35
|
+
|
|
36
|
+
## Dynamic Routing
|
|
37
|
+
|
|
38
|
+
If the directory name of the route file is named with `[]`, the generated route will be used as a dynamic route. For example, the following file directory:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
└── routes
|
|
42
|
+
├── [id]
|
|
43
|
+
│ └── page.tsx
|
|
44
|
+
├── blog
|
|
45
|
+
│ └── page.tsx
|
|
46
|
+
└── page.tsx
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The `routes/[id]/page.tsx` file will be converted to the `/:id` route. Except for the `/blog` route that can be matched exactly, all other `/xxx` routes will be matched to this route.
|
|
50
|
+
|
|
51
|
+
In the component, you can use [useParams](/apis/app/runtime/router/router.md#useparams) to obtain the corresponding named parameter.
|
|
52
|
+
|
|
53
|
+
When using the [loader](/guides/basic-features/data/data-fetch.md#the-loader-function) function to obtain data, `params` will be passed as an input parameter to the `loader` function, and the corresponding parameter can be obtained through the attribute of `params`.
|
|
54
|
+
|
|
55
|
+
## Layout Component
|
|
56
|
+
|
|
57
|
+
In the following example, a common layout component can be added to all route components by adding `layout.tsx`:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
.
|
|
61
|
+
└── routes
|
|
62
|
+
├── layout.tsx
|
|
63
|
+
├── page.tsx
|
|
64
|
+
└── user
|
|
65
|
+
├── layout.tsx
|
|
66
|
+
└── page.tsx
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
In the layout component, you can use `<Outlet>` to represent the child components:
|
|
70
|
+
|
|
71
|
+
```tsx title=routes/layout.tsx
|
|
72
|
+
import { Link, Outlet, useLoaderData } from '@modern-js/runtime/router';
|
|
73
|
+
|
|
74
|
+
export default () => {
|
|
75
|
+
return (
|
|
76
|
+
<>
|
|
77
|
+
<Outlet></Outlet>
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
:::note
|
|
84
|
+
`<Outlet>` is an API provided by React Router. For details, see [Outlet](https://reactrouter.com/en/main/components/outlet#outlet).
|
|
85
|
+
|
|
86
|
+
:::
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# useHonoContext
|
|
2
|
+
|
|
3
|
+
Used to obtain backend request context in an integrated BFF function.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { useHonoContext } from '@modern-js/server-runtime';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Function Signature
|
|
12
|
+
|
|
13
|
+
`function useHonoContext(): Context`
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
Developers can use `context` to obtain more request information, such as setting response headers:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { useHonoContext } from '@modern-js/server-runtime';
|
|
21
|
+
|
|
22
|
+
export async function get() {
|
|
23
|
+
const c = useHonoContext();
|
|
24
|
+
c.res.headers.set('x-bff-api', 'true');
|
|
25
|
+
// ...
|
|
26
|
+
}
|
|
27
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# createRoot
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createRoot } from '@modern-js/runtime/react';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Function Signature
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
export function createRoot(UserApp?: React.ComponentType | null): React.ComponentType<any>;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Parameters
|
|
18
|
+
|
|
19
|
+
- `UserApp`: an optional parameter, and the default is the component exported from `App.tsx`.
|