@modern-js/app-tools 3.6.0 → 3.8.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/bin/modern-bundle-docs.js +7 -0
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +5 -1
- 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 +52 -14
- package/dist/cjs/plugins/analyze/index.js +2 -2
- package/dist/cjs/plugins/analyze/utils.js +3 -2
- package/dist/cjs/plugins/initialize/index.js +4 -3
- package/dist/cjs/plugins/serverBuild.js +3 -2
- package/dist/esm/builder/generator/createBuilderProviderConfig.mjs +5 -1
- 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/initialize/index.mjs +4 -3
- package/dist/esm/plugins/serverBuild.mjs +3 -2
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.mjs +5 -1
- 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/initialize/index.mjs +4 -3
- package/dist/esm-node/plugins/serverBuild.mjs +3 -2
- 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/types/config/dev.d.ts +6 -0
- package/docs/apis/app/commands.md +241 -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-hono-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 +280 -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 +253 -0
- package/docs/community/releases.md +27 -0
- package/docs/community/showcase.md +34 -0
- package/docs/community/team.md +14 -0
- package/docs/configure/app/bff/cross-project.md +20 -0
- package/docs/configure/app/bff/prefix.md +29 -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 +16 -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 +39 -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/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 +26 -0
- package/docs/configure/app/server/ssr-by-entries.md +25 -0
- package/docs/configure/app/server/ssr.md +78 -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 +109 -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/extend-server.md +120 -0
- package/docs/guides/advanced-features/bff/frameworks.md +124 -0
- package/docs/guides/advanced-features/bff/function.md +314 -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 +231 -0
- package/docs/guides/advanced-features/international/best-practices.md +286 -0
- package/docs/guides/advanced-features/international/configuration.md +227 -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 +130 -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 +69 -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 +62 -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 +525 -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 +498 -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 +36 -0
- package/docs/guides/get-started/quick-start.md +236 -0
- package/docs/guides/get-started/tech-stack.md +82 -0
- package/docs/guides/get-started/upgrade.md +123 -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 +118 -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 +963 -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 +285 -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 +48 -15
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Tailwind Plugin Changes
|
|
2
|
+
|
|
3
|
+
Modern.js 3.0 recommends integrating Tailwind CSS through Rsbuild's native approach, no longer relying on the `@modern-js/plugin-tailwindcss` plugin, to fully utilize Rsbuild's more flexible configuration capabilities and better build experience.
|
|
4
|
+
|
|
5
|
+
## Migration Steps
|
|
6
|
+
|
|
7
|
+
The migration operations in this section are only required if the project uses the `@modern-js/plugin-tailwindcss` plugin and the `tailwindcss` version is v2 or v3.
|
|
8
|
+
|
|
9
|
+
### 1. Remove Old Plugin
|
|
10
|
+
|
|
11
|
+
Remove the `@modern-js/plugin-tailwindcss` dependency and configuration.
|
|
12
|
+
|
|
13
|
+
**2.0 Version:**
|
|
14
|
+
|
|
15
|
+
```ts title="modern.config.ts"
|
|
16
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
17
|
+
import tailwindcssPlugin from '@modern-js/plugin-tailwindcss';
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [tailwindcssPlugin()],
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**3.0 Version:**
|
|
25
|
+
|
|
26
|
+
```ts title="modern.config.ts"
|
|
27
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
28
|
+
|
|
29
|
+
export default defineConfig({
|
|
30
|
+
plugins: [],
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Also remove the `@modern-js/plugin-tailwindcss` dependency from `package.json`.
|
|
35
|
+
|
|
36
|
+
### 2. Configure PostCSS
|
|
37
|
+
|
|
38
|
+
Create or update the `postcss.config.cjs` file.
|
|
39
|
+
|
|
40
|
+
```js title="postcss.config.cjs"
|
|
41
|
+
module.exports = {
|
|
42
|
+
plugins: {
|
|
43
|
+
tailwindcss: {},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 3. Tailwind CSS Configuration Migration
|
|
49
|
+
|
|
50
|
+
**Single Configuration Case**:
|
|
51
|
+
|
|
52
|
+
- If only configured in `tailwind.config.{ts,js}`, no additional processing is needed
|
|
53
|
+
- If only configured in `modern.config.ts`, you need to migrate Tailwind-related configurations to `tailwind.config.{ts,js}`
|
|
54
|
+
|
|
55
|
+
**Dual Configuration Case**:
|
|
56
|
+
|
|
57
|
+
If both `tailwind.config.{ts,js}` and `modern.config.ts` have configurations, you need to merge the configurations from both and migrate the merged configuration to `tailwind.config.{ts,js}`.
|
|
58
|
+
|
|
59
|
+
**Special Directory Handling**:
|
|
60
|
+
|
|
61
|
+
If the project has storybook or config/html directories, you need to add them to the `content` in `tailwind.config.{ts,js}`:
|
|
62
|
+
|
|
63
|
+
```ts title="tailwind.config.ts"
|
|
64
|
+
export default {
|
|
65
|
+
content: [
|
|
66
|
+
'./src/**/*.{js,jsx,ts,tsx}',
|
|
67
|
+
'./storybook/**/*', // If storybook directory exists
|
|
68
|
+
'./config/html/**/*.{html,ejs,hbs}', // If config/html directory exists
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 4. CSS Style Import
|
|
74
|
+
|
|
75
|
+
Change the CSS import method to the `@tailwind` directive approach.
|
|
76
|
+
|
|
77
|
+
**2.0 Version:**
|
|
78
|
+
|
|
79
|
+
```css
|
|
80
|
+
@import 'tailwindcss/base.css';
|
|
81
|
+
@import 'tailwindcss/components.css';
|
|
82
|
+
@import 'tailwindcss/utilities.css';
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**3.0 Version:**
|
|
86
|
+
|
|
87
|
+
```css
|
|
88
|
+
@tailwind base;
|
|
89
|
+
@tailwind components;
|
|
90
|
+
@tailwind utilities;
|
|
91
|
+
```
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Custom Web Server Changes
|
|
2
|
+
|
|
3
|
+
This chapter covers upgrades for two types of legacy custom Server APIs:
|
|
4
|
+
|
|
5
|
+
- **unstableMiddleware**
|
|
6
|
+
- **Hook**
|
|
7
|
+
|
|
8
|
+
These two approaches are mutually exclusive in the legacy version. When migrating, please choose the corresponding path based on the capabilities actually used in the project.
|
|
9
|
+
|
|
10
|
+
## unstableMiddleware
|
|
11
|
+
|
|
12
|
+
### Core Differences
|
|
13
|
+
|
|
14
|
+
- **File Structure**: `server/index.ts` → `server/modern.server.ts`
|
|
15
|
+
- **Export Method**: `unstableMiddleware` array → `defineServerConfig`
|
|
16
|
+
- **Context API**: Modern.js Server Context → Hono Context (`c.req`/`c.res`)
|
|
17
|
+
- **Middleware Execution**: Legacy version could skip calling `next()`, new version must call it for subsequent chain execution
|
|
18
|
+
- **Response Method**: `c.response.raw()` → `c.text()` / `c.json()`
|
|
19
|
+
|
|
20
|
+
### File and Export
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
// Legacy - server/index.ts
|
|
24
|
+
export const unstableMiddleware: UnstableMiddleware[] = [middleware1, middleware2];
|
|
25
|
+
|
|
26
|
+
// New - server/modern.server.ts
|
|
27
|
+
import { defineServerConfig } from '@modern-js/server-runtime';
|
|
28
|
+
|
|
29
|
+
export default defineServerConfig({
|
|
30
|
+
middlewares: [
|
|
31
|
+
{ name: 'middleware1', handler: middleware1 },
|
|
32
|
+
{ name: 'middleware2', handler: middleware2 },
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Type and next Call
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
// Legacy
|
|
41
|
+
import type { UnstableMiddleware, UnstableMiddlewareContext } from '@modern-js/server-runtime';
|
|
42
|
+
const middleware: UnstableMiddleware = async (c: UnstableMiddlewareContext, next) => {
|
|
43
|
+
return c.response.raw('response'); // Will continue rendering even without calling next
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// New
|
|
47
|
+
import { defineServerConfig, type MiddlewareHandler } from '@modern-js/server-runtime';
|
|
48
|
+
const middleware: MiddlewareHandler = async (c, next) => {
|
|
49
|
+
await next(); // Must call
|
|
50
|
+
return c.text('response');
|
|
51
|
+
};
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Context API Comparison
|
|
55
|
+
|
|
56
|
+
| Legacy API | New API | Description |
|
|
57
|
+
| -------------------- | ---------------------- | -------------------- |
|
|
58
|
+
| `c.request.cookie` | `getCookie(c, 'key')` | Cookie reading |
|
|
59
|
+
| `c.req.cookie()` | `getCookie(c, 'key')` | Hono v4 deprecated |
|
|
60
|
+
| `c.request.pathname` | `c.req.path` | Request path |
|
|
61
|
+
| `c.request.host` | `c.req.header('Host')` | Request host |
|
|
62
|
+
| `c.request.query` | `c.req.query()` | Query parameters |
|
|
63
|
+
| `c.request.headers` | `c.req.header()` | Request headers |
|
|
64
|
+
| `c.response.status` | `c.status()` | Response status code |
|
|
65
|
+
| `c.response.set` | `c.res.headers.set` | Set response headers |
|
|
66
|
+
| `c.response.raw` | `c.text` / `c.json` | Response body |
|
|
67
|
+
|
|
68
|
+
## afterRender Hook
|
|
69
|
+
|
|
70
|
+
The `afterRender` Hook is used to process HTML after page rendering is complete. In the new version, you need to use `renderMiddlewares` to achieve the same functionality.
|
|
71
|
+
|
|
72
|
+
### Core Differences
|
|
73
|
+
|
|
74
|
+
- **File Structure**: `server/index.ts` → `server/modern.server.ts`
|
|
75
|
+
- **Export Method**: `afterRender` in `hook` object → `renderMiddlewares` in `defineServerConfig`
|
|
76
|
+
- **Processing Method**: Direct HTML string modification → Get and modify response through middleware
|
|
77
|
+
|
|
78
|
+
### Migration Example
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
// Legacy - server/index.ts
|
|
82
|
+
export const afterRender = (ctx, next) => {
|
|
83
|
+
ctx.template = ctx.template
|
|
84
|
+
.replace('<head>', '<head><meta name="author" content="ByteDance">')
|
|
85
|
+
.replace('<body>', '<body><div id="loading">Loading...</div>')
|
|
86
|
+
.replace('</body>', '<script>console.log("Page loaded")</script></body>');
|
|
87
|
+
next();
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// New - server/modern.server.ts
|
|
91
|
+
import { defineServerConfig, type MiddlewareHandler } from '@modern-js/server-runtime';
|
|
92
|
+
|
|
93
|
+
const renderMiddleware: MiddlewareHandler = async (c, next) => {
|
|
94
|
+
await next(); // Wait for page rendering first
|
|
95
|
+
const { res } = c;
|
|
96
|
+
const html = await res.text();
|
|
97
|
+
|
|
98
|
+
const modified = html
|
|
99
|
+
.replace('<head>', '<head><meta name="author" content="ByteDance">')
|
|
100
|
+
.replace('<body>', '<body><div id="loading">Loading...</div>')
|
|
101
|
+
.replace('</body>', '<script>console.log("Page loaded")</script></body>');
|
|
102
|
+
|
|
103
|
+
c.res = c.body(modified, { status: res.status, headers: res.headers });
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export default defineServerConfig({
|
|
107
|
+
renderMiddlewares: [{ name: 'custom-content-injection', handler: renderMiddleware }],
|
|
108
|
+
});
|
|
109
|
+
```
|
package/docs/index.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[NEWModern.js 3.0 is released!→](/community/blog/v3-release-note)
|
|
2
|
+
|
|
3
|
+
# Modern.js 3.0A Progressive React Framework for modern web development
|
|
4
|
+
|
|
5
|
+
[Introduction](/guides/get-started/introduction)[Quick Start](/guides/get-started/quick-start)
|
|
6
|
+
|
|
7
|
+
[Rust BundlerBuilt with Rspack bundler for faster build speed.](/guides/concept/builder)[Integrated BFFDevelop BFF code in the same project, enjoy simple function calls.](/guides/advanced-features/bff/index)[Nested RoutesFile-as-route, comes with lots performance optimizations.](/guides/basic-features/routes/routes)[Multi-Rendering ModeRSC, SSR, SSG, all out of the box for you.](/guides/basic-features/render/ssr)[CSS SolutionsCSS Modules, CSS-in-JS, Tailwind CSS, take your pick.](/guides/basic-features/css/css)[Easy to ConfigureLaunch with zero configuration, then everything is configurable.](/configure/app/usage)
|
|
8
|
+
|
|
9
|
+
Guide
|
|
10
|
+
|
|
11
|
+
- [Quick Start](/guides/get-started/quick-start)
|
|
12
|
+
- [Core Concept](/guides/concept/entries)
|
|
13
|
+
- [Basic Features](/guides/basic-features/routes)
|
|
14
|
+
- [Advanced Features](/guides/advanced-features/bff)
|
|
15
|
+
|
|
16
|
+
API
|
|
17
|
+
|
|
18
|
+
- [Configuration](/configure/app/usage)
|
|
19
|
+
- [Command](/apis/app/commands)
|
|
20
|
+
- [Runtime](/apis/app/runtime/core/bootstrap)
|
|
21
|
+
- [Conventions](/apis/app/hooks/src/app)
|
|
22
|
+
|
|
23
|
+
Topic
|
|
24
|
+
|
|
25
|
+
- [Module Federation](/guides/topic-detail/module-federation/introduce)
|
|
26
|
+
- [Plugin System](/plugin/plugin-system)
|
|
27
|
+
|
|
28
|
+
Help
|
|
29
|
+
|
|
30
|
+
- [Changelog](https://github.com/web-infra-dev/modern.js/releases)
|
|
31
|
+
- [GitHub Issues](https://github.com/web-infra-dev/modern.js/issues)
|
|
32
|
+
- [Github Discussion](https://github.com/web-infra-dev/modern.js/discussions)
|
|
33
|
+
|