@modern-js/main-doc 3.0.0-alpha.0 → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/en/apis/app/commands.mdx +6 -30
- package/docs/en/components/bff-upload.mdx +3 -5
- package/docs/en/components/bundler.mdx +1 -1
- package/docs/en/components/enable-bff.mdx +6 -2
- package/docs/en/components/enable-ssg.mdx +1 -0
- package/docs/en/components/esbuild.mdx +2 -2
- package/docs/en/components/extend-bff-function.mdx +2 -4
- package/docs/en/components/hono.mdx +119 -0
- package/docs/en/components/international/custom-instance-code.mdx +16 -0
- package/docs/en/components/international/init-options-desc.mdx +1 -0
- package/docs/en/components/international/install-command.mdx +15 -1
- package/docs/en/components/international/instance-code.mdx +26 -0
- package/docs/en/configure/app/builder-plugins.mdx +1 -2
- package/docs/en/configure/app/dev/server.mdx +108 -0
- package/docs/en/configure/app/experiments/source-build.mdx +0 -1
- package/docs/en/configure/app/output/assets-retry.mdx +1 -1
- package/docs/en/configure/app/output/disable-inline-runtime-chunk.mdx +2 -2
- package/docs/en/configure/app/output/filename.mdx +2 -4
- package/docs/en/configure/app/output/temp-dir.mdx +3 -3
- package/docs/en/configure/app/performance/build-cache.mdx +1 -1
- package/docs/en/configure/app/performance/profile.mdx +1 -1
- package/docs/en/configure/app/plugins.mdx +1 -3
- package/docs/en/configure/app/runtime/router.mdx +0 -4
- package/docs/en/configure/app/security/sri.mdx +0 -1
- package/docs/en/configure/app/source/alias.mdx +1 -1
- package/docs/en/configure/app/source/enable-async-entry.mdx +1 -1
- package/docs/en/configure/app/source/include.mdx +2 -14
- package/docs/en/configure/app/tools/dev-server.mdx +8 -8
- package/docs/en/configure/app/usage.mdx +0 -12
- package/docs/en/guides/_meta.json +5 -0
- package/docs/en/guides/advanced-features/bff/_meta.json +9 -1
- package/docs/en/guides/advanced-features/bff/cross-project.mdx +1 -1
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -15
- package/docs/en/guides/advanced-features/bff/function.mdx +4 -4
- package/docs/en/guides/advanced-features/bff/operators.mdx +628 -0
- package/docs/en/guides/advanced-features/bff/sdk.mdx +17 -9
- package/docs/en/guides/advanced-features/bff/upload.mdx +3 -1
- package/docs/en/guides/advanced-features/international/configuration.mdx +7 -16
- package/docs/en/guides/advanced-features/international/quick-start.mdx +4 -32
- package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +1 -1
- package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +18 -4
- package/docs/en/guides/advanced-features/rspack-start.mdx +1 -1
- package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +62 -5
- package/docs/en/guides/basic-features/data/data-cache.mdx +60 -76
- package/docs/en/guides/basic-features/data/data-fetch.mdx +15 -14
- package/docs/en/guides/basic-features/debug/proxy.mdx +6 -9
- package/docs/en/guides/basic-features/render/rsc.mdx +24 -19
- package/docs/en/guides/basic-features/render/ssg.mdx +4 -9
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +0 -4
- package/docs/en/guides/basic-features/static-assets/svg-assets.mdx +0 -4
- package/docs/en/guides/get-started/tech-stack.mdx +1 -1
- package/docs/en/guides/upgrade/_meta.json +1 -0
- package/docs/en/guides/upgrade/config.mdx +936 -0
- package/docs/en/guides/upgrade/entry.mdx +463 -0
- package/docs/en/guides/upgrade/other.mdx +83 -0
- package/docs/en/guides/upgrade/overview.mdx +33 -0
- package/docs/en/guides/upgrade/tailwindcss.mdx +130 -0
- package/docs/en/guides/upgrade/web-server.mdx +91 -0
- package/docs/en/plugin/_meta.json +5 -0
- package/docs/en/plugin/cli-plugins/_meta.json +1 -1
- package/docs/en/plugin/cli-plugins/api.mdx +13 -63
- package/docs/en/plugin/cli-plugins/life-cycle.mdx +0 -4
- package/docs/en/plugin/introduction.mdx +8 -20
- package/docs/en/plugin/plugin-system.mdx +3 -3
- package/docs/en/plugin/runtime-plugins/_meta.json +1 -1
- package/docs/en/plugin/runtime-plugins/api.mdx +1 -1
- package/docs/en/plugin/server-plugins/_meta.json +1 -0
- package/docs/en/plugin/server-plugins/api.mdx +210 -1
- package/docs/en/plugin/server-plugins/life-cycle.mdx +41 -1
- package/docs/zh/apis/app/commands.mdx +6 -30
- package/docs/zh/components/bff-operator-code.mdx +5 -0
- package/docs/zh/components/bff-upload.mdx +0 -2
- package/docs/zh/components/bundler.mdx +1 -1
- package/docs/zh/components/enable-bff.mdx +6 -2
- package/docs/zh/components/enable-ssg.mdx +3 -1
- package/docs/zh/components/esbuild.mdx +2 -2
- package/docs/zh/components/extend-bff-function.mdx +2 -4
- package/docs/zh/components/hono.mdx +119 -0
- package/docs/zh/components/international/custom-instance-code.mdx +16 -0
- package/docs/zh/components/international/init-options-desc.mdx +1 -0
- package/docs/zh/components/international/install-command.mdx +15 -0
- package/docs/zh/components/international/instance-code.mdx +26 -0
- package/docs/zh/configure/app/builder-plugins.mdx +1 -2
- package/docs/zh/configure/app/dev/server.mdx +109 -2
- package/docs/zh/configure/app/experiments/source-build.mdx +0 -1
- package/docs/zh/configure/app/output/assets-retry.mdx +1 -1
- package/docs/zh/configure/app/output/disable-inline-runtime-chunk.mdx +2 -2
- package/docs/zh/configure/app/output/filename.mdx +2 -4
- package/docs/zh/configure/app/output/temp-dir.mdx +3 -3
- package/docs/zh/configure/app/performance/build-cache.mdx +1 -1
- package/docs/zh/configure/app/performance/profile.mdx +1 -1
- package/docs/zh/configure/app/plugins.mdx +1 -2
- package/docs/zh/configure/app/runtime/router.mdx +0 -4
- package/docs/zh/configure/app/security/sri.mdx +0 -1
- package/docs/zh/configure/app/source/alias.mdx +1 -1
- package/docs/zh/configure/app/source/enable-async-entry.mdx +1 -1
- package/docs/zh/configure/app/source/include.mdx +2 -16
- package/docs/zh/configure/app/tools/dev-server.mdx +5 -5
- package/docs/zh/configure/app/usage.mdx +0 -12
- package/docs/zh/guides/advanced-features/bff/_meta.json +9 -1
- package/docs/zh/guides/advanced-features/bff/frameworks.mdx +2 -16
- package/docs/zh/guides/advanced-features/bff/operators.mdx +628 -0
- package/docs/zh/guides/advanced-features/bff/sdk.mdx +19 -12
- package/docs/zh/guides/advanced-features/bff/upload.mdx +3 -1
- package/docs/zh/guides/advanced-features/international/configuration.mdx +7 -16
- package/docs/zh/guides/advanced-features/international/quick-start.mdx +2 -25
- package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +1 -1
- package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +18 -4
- package/docs/zh/guides/advanced-features/server-monitor/monitors.mdx +60 -5
- package/docs/zh/guides/basic-features/data/data-cache.mdx +47 -54
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +9 -12
- package/docs/zh/guides/basic-features/debug/proxy.mdx +4 -7
- package/docs/zh/guides/basic-features/render/rsc.mdx +23 -37
- package/docs/zh/guides/basic-features/render/ssr-cache.mdx +0 -4
- package/docs/zh/guides/basic-features/static-assets/svg-assets.mdx +0 -4
- package/docs/zh/guides/get-started/tech-stack.mdx +1 -1
- package/docs/zh/guides/troubleshooting/builder.mdx +1 -1
- package/docs/zh/guides/upgrade/config.mdx +132 -1
- package/docs/zh/plugin/_meta.json +5 -0
- package/docs/zh/plugin/cli-plugins/_meta.json +1 -1
- package/docs/zh/plugin/cli-plugins/api.mdx +15 -65
- package/docs/zh/plugin/cli-plugins/life-cycle.mdx +0 -4
- package/docs/zh/plugin/introduction.mdx +4 -16
- package/docs/zh/plugin/plugin-system.mdx +3 -14
- package/docs/zh/plugin/runtime-plugins/_meta.json +1 -1
- package/docs/zh/plugin/runtime-plugins/api.mdx +1 -1
- package/docs/zh/plugin/server-plugins/_meta.json +1 -0
- package/docs/zh/plugin/server-plugins/api.mdx +210 -1
- package/docs/zh/plugin/server-plugins/life-cycle.mdx +41 -1
- package/package.json +2 -2
- package/src/components/FrameworkCode/index.tsx +605 -0
- package/docs/en/configure/app/performance/bundle-analyze.mdx +0 -24
- package/docs/en/configure/app/tools/babel.mdx +0 -225
- package/docs/en/plugin/cli-plugins/migration.mdx +0 -83
- package/docs/en/plugin/runtime-plugins/migration.mdx +0 -110
- package/docs/zh/components/default-mwa-generate.mdx +0 -4
- package/docs/zh/configure/app/performance/bundle-analyze.mdx +0 -24
- package/docs/zh/configure/app/tools/babel.mdx +0 -224
- package/docs/zh/plugin/cli-plugins/migration.mdx +0 -83
- package/docs/zh/plugin/runtime-plugins/migration.mdx +0 -110
- /package/docs/en/components/{router-legacy-tip.mdx → upgrade-config-deploy.mdx} +0 -0
- /package/docs/zh/components/{router-legacy-tip.mdx → upgrade-config-deploy.mdx} +0 -0
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
# Entry Changes
|
|
2
|
+
|
|
3
|
+
This chapter introduces changes related to page entries when upgrading from Modern.js 2.0 to 3.0.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Modern.js 3.0 has optimized and simplified the entry mechanism. The main changes include:
|
|
8
|
+
|
|
9
|
+
- **Entry File Naming Change**: Custom entry files changed from `index.[jt]sx` to `entry.[jt]sx`
|
|
10
|
+
- **Bootstrap Function Replacement**: Use the new `createRoot` and `render` APIs
|
|
11
|
+
- **Runtime Configuration Migration**: `App.config` and `config` exports from `routes/layout` need to be migrated
|
|
12
|
+
- **Initialization Logic Migration**: `App.init` and `init` exports from `routes/layout` need to be changed to runtime plugins
|
|
13
|
+
|
|
14
|
+
## Entry Type Identification
|
|
15
|
+
|
|
16
|
+
Before starting migration, first identify the entry type used in your project.
|
|
17
|
+
|
|
18
|
+
### Entry Identification Conditions
|
|
19
|
+
|
|
20
|
+
Modern.js scans directories and identifies entries that meet **any** of the following conditions:
|
|
21
|
+
|
|
22
|
+
1. **Has a `routes/` directory** → Convention-based routing entry
|
|
23
|
+
2. **Has an `App.[jt]sx?` file** → Self-controlled routing entry
|
|
24
|
+
3. **Has an `index.[jt]sx?` file (2.0) or `entry.[jt]sx?` file (3.0)** → Custom entry
|
|
25
|
+
|
|
26
|
+
### Single Entry vs Multiple Entries
|
|
27
|
+
|
|
28
|
+
**Single Entry Application**: Scans the `src/` directory by default
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
src/
|
|
32
|
+
├── routes/ # or
|
|
33
|
+
├── App.tsx # or
|
|
34
|
+
└── index.tsx # 2.0 version
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Multiple Entry Application**: Scans first-level subdirectories under `src/`
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
src/
|
|
41
|
+
├── entry1/
|
|
42
|
+
│ └── routes/ # Each subdirectory is an entry
|
|
43
|
+
└── entry2/
|
|
44
|
+
└── App.tsx
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
:::tip
|
|
48
|
+
You can modify the entry scanning directory through the [source.entriesDir](/configure/app/source/entries-dir) configuration.
|
|
49
|
+
:::
|
|
50
|
+
|
|
51
|
+
## Migration Steps
|
|
52
|
+
|
|
53
|
+
The migration operations in this section only need to be performed when the corresponding usage actually exists in the project, such as `bootstrap` function, `App.config/App.init`, `config/init` functions in `routes/layout.tsx`, etc.
|
|
54
|
+
|
|
55
|
+
### 1. Custom Entry File Rename
|
|
56
|
+
|
|
57
|
+
If your project uses a custom entry file (`index.[jt]sx`), you need to rename it to `entry.[jt]sx`.
|
|
58
|
+
|
|
59
|
+
**2.0 Version:**
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
src/
|
|
63
|
+
└── index.tsx
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**3.0 Version:**
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
src/
|
|
70
|
+
└── entry.tsx
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 2. Bootstrap Function Migration
|
|
74
|
+
|
|
75
|
+
If your entry file exports a function that receives `App` and `bootstrap` parameters, you need to use the new API instead.
|
|
76
|
+
|
|
77
|
+
**2.0 Version:**
|
|
78
|
+
|
|
79
|
+
```tsx title="src/index.tsx"
|
|
80
|
+
export default (App: React.ComponentType, bootstrap: () => void) => {
|
|
81
|
+
// Perform initialization operations
|
|
82
|
+
initSomething().then(() => {
|
|
83
|
+
bootstrap();
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**3.0 Version:**
|
|
89
|
+
|
|
90
|
+
```tsx title="src/entry.tsx"
|
|
91
|
+
import { createRoot } from '@modern-js/runtime/react';
|
|
92
|
+
import { render } from '@modern-js/runtime/browser';
|
|
93
|
+
|
|
94
|
+
// Create root component
|
|
95
|
+
const ModernRoot = createRoot();
|
|
96
|
+
|
|
97
|
+
// Perform initialization operations
|
|
98
|
+
async function beforeRender() {
|
|
99
|
+
await initSomething();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Render application
|
|
103
|
+
beforeRender().then(() => {
|
|
104
|
+
render(<ModernRoot />);
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
:::info Note
|
|
109
|
+
|
|
110
|
+
- The component returned by `createRoot()` corresponds to the component generated by the `routes/` directory or exported by `App.tsx`
|
|
111
|
+
- The `render()` function is used to handle rendering and mounting components
|
|
112
|
+
|
|
113
|
+
:::
|
|
114
|
+
|
|
115
|
+
### 3. App.config Migration
|
|
116
|
+
|
|
117
|
+
If you defined `App.config` in `App.[tj]sx`, you need to migrate it to the runtime configuration file.
|
|
118
|
+
|
|
119
|
+
**2.0 Version:**
|
|
120
|
+
|
|
121
|
+
```tsx title="src/App.tsx"
|
|
122
|
+
const App = () => {
|
|
123
|
+
return <div>Hello</div>;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
App.config = {
|
|
127
|
+
router: {
|
|
128
|
+
supportHtml5History: true,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export default App;
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**3.0 Version:**
|
|
136
|
+
|
|
137
|
+
Create `modern.runtime.ts` in the same directory as the entry:
|
|
138
|
+
|
|
139
|
+
```ts title="src/modern.runtime.ts"
|
|
140
|
+
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
141
|
+
|
|
142
|
+
export default defineRuntimeConfig({
|
|
143
|
+
router: {
|
|
144
|
+
supportHtml5History: true,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
:::warning Note
|
|
150
|
+
Modern.js 3.0 no longer supports configuring runtime in `modern.config.ts`, you must use the `modern.runtime.ts` file.
|
|
151
|
+
:::
|
|
152
|
+
|
|
153
|
+
### 4. App.init Migration
|
|
154
|
+
|
|
155
|
+
If you defined `App.init` in `App.[tj]sx`, you need to change it to a runtime plugin.
|
|
156
|
+
|
|
157
|
+
**2.0 Version:**
|
|
158
|
+
|
|
159
|
+
```tsx title="src/App.tsx"
|
|
160
|
+
const App = () => {
|
|
161
|
+
return <div>Hello</div>;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
App.init = context => {
|
|
165
|
+
context.store = createStore();
|
|
166
|
+
context.request = (url: string) => fetch(url);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export default App;
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**3.0 Version:**
|
|
173
|
+
|
|
174
|
+
```ts title="src/modern.runtime.ts"
|
|
175
|
+
import type { RuntimePlugin } from '@modern-js/runtime';
|
|
176
|
+
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
177
|
+
|
|
178
|
+
const initPlugin = (): RuntimePlugin => ({
|
|
179
|
+
name: 'init-plugin',
|
|
180
|
+
setup: api => {
|
|
181
|
+
return {
|
|
182
|
+
init({ context }) {
|
|
183
|
+
context.store = createStore();
|
|
184
|
+
context.request = (url: string) => fetch(url);
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
export default defineRuntimeConfig({
|
|
191
|
+
plugins: [initPlugin()],
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### 5. config Export Migration from routes/layout.tsx
|
|
196
|
+
|
|
197
|
+
If you exported a `config` function in `routes/layout.tsx`, you need to migrate it to the runtime configuration file.
|
|
198
|
+
|
|
199
|
+
**2.0 Version:**
|
|
200
|
+
|
|
201
|
+
```tsx title="src/routes/layout.tsx"
|
|
202
|
+
export const config = () => {
|
|
203
|
+
return {
|
|
204
|
+
router: {
|
|
205
|
+
supportHtml5History: true,
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export default function Layout() {
|
|
211
|
+
return <Outlet />;
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**3.0 Version:**
|
|
216
|
+
|
|
217
|
+
```tsx title="src/routes/layout.tsx"
|
|
218
|
+
export default function Layout() {
|
|
219
|
+
return <Outlet />;
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
```ts title="src/modern.runtime.ts"
|
|
224
|
+
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
225
|
+
|
|
226
|
+
export default defineRuntimeConfig({
|
|
227
|
+
router: {
|
|
228
|
+
supportHtml5History: true,
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### 6. init Export Migration from routes/layout.tsx
|
|
234
|
+
|
|
235
|
+
If you exported an `init` function in `routes/layout.tsx`, you need to change it to a runtime plugin.
|
|
236
|
+
|
|
237
|
+
**2.0 Version:**
|
|
238
|
+
|
|
239
|
+
```tsx title="src/routes/layout.tsx"
|
|
240
|
+
export const init = context => {
|
|
241
|
+
context.request = (url: string) => fetch(url);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export default function Layout() {
|
|
245
|
+
return <Outlet />;
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**3.0 Version:**
|
|
250
|
+
|
|
251
|
+
```tsx title="src/routes/layout.tsx"
|
|
252
|
+
export default function Layout() {
|
|
253
|
+
return <Outlet />;
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
```ts title="src/modern.runtime.ts"
|
|
258
|
+
import type { RuntimePlugin } from '@modern-js/runtime';
|
|
259
|
+
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
260
|
+
|
|
261
|
+
const initPlugin = (): RuntimePlugin => ({
|
|
262
|
+
name: 'init-plugin',
|
|
263
|
+
setup: api => {
|
|
264
|
+
return {
|
|
265
|
+
init({ context }) {
|
|
266
|
+
context.request = (url: string) => fetch(url);
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
export default defineRuntimeConfig({
|
|
273
|
+
plugins: [initPlugin()],
|
|
274
|
+
});
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Multi-Entry Application Migration Notes
|
|
278
|
+
|
|
279
|
+
For multi-entry applications, you need to use function-form configuration in `src/modern.runtime.ts`, returning different runtime configurations based on entry names.
|
|
280
|
+
|
|
281
|
+
### Configuration Method
|
|
282
|
+
|
|
283
|
+
**Directory Structure:**
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
src/
|
|
287
|
+
├── modern.runtime.ts # Unified runtime configuration file
|
|
288
|
+
├── entry1/
|
|
289
|
+
│ └── routes/
|
|
290
|
+
└── entry2/
|
|
291
|
+
└── App.tsx
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
**Configuration Example:**
|
|
295
|
+
|
|
296
|
+
```ts title="src/modern.runtime.ts"
|
|
297
|
+
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
298
|
+
|
|
299
|
+
export default defineRuntimeConfig(entryName => {
|
|
300
|
+
// Common configuration
|
|
301
|
+
const commonConfig = {
|
|
302
|
+
plugins: [commonPlugin()],
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// Return specific configuration based on entry name
|
|
306
|
+
if (entryName === 'entry1') {
|
|
307
|
+
return {
|
|
308
|
+
...commonConfig,
|
|
309
|
+
router: {
|
|
310
|
+
supportHtml5History: true,
|
|
311
|
+
},
|
|
312
|
+
plugins: [...commonConfig.plugins, entry1Plugin()],
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (entryName === 'entry2') {
|
|
317
|
+
return {
|
|
318
|
+
...commonConfig,
|
|
319
|
+
router: {
|
|
320
|
+
supportHtml5History: false,
|
|
321
|
+
},
|
|
322
|
+
plugins: [...commonConfig.plugins, entry2Plugin()],
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Default configuration
|
|
327
|
+
return commonConfig;
|
|
328
|
+
});
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
:::info Note
|
|
332
|
+
|
|
333
|
+
- The `entryName` parameter corresponds to the entry directory name
|
|
334
|
+
- Main entry (same name as `name` in `package.json`): the directory name is passed in
|
|
335
|
+
- Other entries: the entry directory name is passed in
|
|
336
|
+
|
|
337
|
+
:::
|
|
338
|
+
|
|
339
|
+
### Migration Notes
|
|
340
|
+
|
|
341
|
+
1. **Merge configurations for the same entry**: If both `App.config/App.init` and `config/init` from `routes/layout.tsx` exist for the same entry, you need to merge them into the corresponding entry configuration in the `src/modern.runtime.ts` file
|
|
342
|
+
|
|
343
|
+
2. **Multiple plugins in parallel**: Multiple runtime plugins can be configured in parallel in the `plugins` array
|
|
344
|
+
|
|
345
|
+
3. **Clean up old code**: After migration is complete, remember to delete from the original files:
|
|
346
|
+
- `App.config` property
|
|
347
|
+
- `App.init` method
|
|
348
|
+
- `config` export from `routes/layout.tsx`
|
|
349
|
+
- `init` export from `routes/layout.tsx`
|
|
350
|
+
|
|
351
|
+
### Migration Example
|
|
352
|
+
|
|
353
|
+
Assume you have a 2.0 version multi-entry application:
|
|
354
|
+
|
|
355
|
+
**2.0 Version Directory Structure:**
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
src/
|
|
359
|
+
├── main/
|
|
360
|
+
│ ├── routes/
|
|
361
|
+
│ │ └── layout.tsx # Contains config and init
|
|
362
|
+
│ └── App.tsx # Contains App.config and App.init
|
|
363
|
+
└── admin/
|
|
364
|
+
└── routes/
|
|
365
|
+
└── layout.tsx # Contains config and init
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
**2.0 Version Configuration:**
|
|
369
|
+
|
|
370
|
+
```tsx title="src/main/App.tsx"
|
|
371
|
+
const App = () => <div>Main App</div>;
|
|
372
|
+
|
|
373
|
+
App.config = {
|
|
374
|
+
router: { supportHtml5History: true },
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
App.init = context => {
|
|
378
|
+
context.mainData = 'main';
|
|
379
|
+
};
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
```tsx title="src/admin/routes/layout.tsx"
|
|
383
|
+
export const config = () => ({
|
|
384
|
+
router: { supportHtml5History: false },
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
export const init = context => {
|
|
388
|
+
context.adminData = 'admin';
|
|
389
|
+
};
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
**3.0 Version After Migration:**
|
|
393
|
+
|
|
394
|
+
```bash
|
|
395
|
+
src/
|
|
396
|
+
├── modern.runtime.ts # New unified configuration file
|
|
397
|
+
├── main/
|
|
398
|
+
│ ├── routes/
|
|
399
|
+
│ │ └── layout.tsx # Removed config and init
|
|
400
|
+
│ └── App.tsx # Removed App.config and App.init
|
|
401
|
+
└── admin/
|
|
402
|
+
└── routes/
|
|
403
|
+
└── layout.tsx # Removed config and init
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
```ts title="src/modern.runtime.ts"
|
|
407
|
+
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
408
|
+
import type { RuntimePlugin } from '@modern-js/runtime';
|
|
409
|
+
|
|
410
|
+
// Main entry initialization plugin
|
|
411
|
+
const mainInitPlugin = (): RuntimePlugin => ({
|
|
412
|
+
name: 'main-init-plugin',
|
|
413
|
+
setup: api => {
|
|
414
|
+
return {
|
|
415
|
+
init({ context }) {
|
|
416
|
+
context.mainData = 'main';
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
// Admin entry initialization plugin
|
|
423
|
+
const adminInitPlugin = (): RuntimePlugin => ({
|
|
424
|
+
name: 'admin-init-plugin',
|
|
425
|
+
setup: api => {
|
|
426
|
+
return {
|
|
427
|
+
init({ context }) {
|
|
428
|
+
context.adminData = 'admin';
|
|
429
|
+
},
|
|
430
|
+
};
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
export default defineRuntimeConfig(entryName => {
|
|
435
|
+
if (entryName === 'main') {
|
|
436
|
+
return {
|
|
437
|
+
router: {
|
|
438
|
+
supportHtml5History: true,
|
|
439
|
+
},
|
|
440
|
+
plugins: [mainInitPlugin()],
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (entryName === 'admin') {
|
|
445
|
+
return {
|
|
446
|
+
router: {
|
|
447
|
+
supportHtml5History: false,
|
|
448
|
+
},
|
|
449
|
+
plugins: [adminInitPlugin()],
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return {};
|
|
454
|
+
});
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
## Related Links
|
|
458
|
+
|
|
459
|
+
- [Page Entries](/guides/concept/entries)
|
|
460
|
+
- [Runtime Configuration](/configure/app/runtime/0-intro)
|
|
461
|
+
- [Runtime Plugins](/plugin/introduction.html#runtime-插件)
|
|
462
|
+
- [source.entries Configuration](/configure/app/source/entries)
|
|
463
|
+
- [source.entriesDir Configuration](/configure/app/source/entries-dir)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Other Important Changes
|
|
2
|
+
|
|
3
|
+
This document introduces other important incompatible changes and related migration instructions when upgrading from Modern.js 2.0 to 3.0.
|
|
4
|
+
|
|
5
|
+
## Webpack Build No Longer Supported
|
|
6
|
+
|
|
7
|
+
Modern.js 3.0 no longer supports using webpack as a build tool, and uses Rspack as the default build bundler. Rspack is implemented in Rust, providing significant build speed improvements compared to webpack, while being highly compatible with webpack configuration, allowing most configurations to be migrated directly.
|
|
8
|
+
|
|
9
|
+
If your project previously used webpack-specific configurations or plugins, you need to check if there are webpack-related custom configurations in the project and confirm whether the webpack plugins used have corresponding Rspack versions.
|
|
10
|
+
|
|
11
|
+
:::tip
|
|
12
|
+
Rspack is highly compatible with webpack configuration, and in most cases it can be used without modification.
|
|
13
|
+
:::
|
|
14
|
+
|
|
15
|
+
## Entry Name Change
|
|
16
|
+
|
|
17
|
+
Modern.js 3.0 changed the default entry name to `index`, and the default built HTML file is `index.html`. `index.html` is the default homepage file for most web servers and requires no additional configuration.
|
|
18
|
+
|
|
19
|
+
If your project's deployment configuration specifies a particular entry file name, you need to update it to `index.html`.
|
|
20
|
+
|
|
21
|
+
## API Import Paths
|
|
22
|
+
|
|
23
|
+
Modern.js 3.0 has adjusted some runtime paths, and related import paths need to be updated. The path mapping is as follows:
|
|
24
|
+
|
|
25
|
+
| Old Path | New Path | Description |
|
|
26
|
+
|---------|---------|------|
|
|
27
|
+
| `@modern-js/runtime/bff` | `@modern-js/plugin-bff/runtime` | BFF runtime path |
|
|
28
|
+
| `@modern-js/runtime/server` | `@modern-js/server-runtime` | Server-side runtime path |
|
|
29
|
+
|
|
30
|
+
## Pages Directory Convention-Based Routing No Longer Supported
|
|
31
|
+
|
|
32
|
+
Modern.js 3.0 no longer supports the `pages` directory convention-based routing introduced in Modern.js 1.0, and now uniformly uses the `routes` directory convention-based routing.
|
|
33
|
+
|
|
34
|
+
If your project uses the `pages` directory, you need to rename the `src/pages` directory to `src/routes` and update all import paths in the project that reference the `pages` directory. For detailed migration steps, please refer to the [Convention-Based Routing documentation](/guides/basic-features/routes/routes).
|
|
35
|
+
|
|
36
|
+
## SSR Mode Default Value Change
|
|
37
|
+
|
|
38
|
+
Modern.js 3.0 changed the default value of `server.ssr.mode` from `'string'` to `'stream'`. This means that when SSR is enabled, streaming rendering is used by default instead of traditional string rendering.
|
|
39
|
+
|
|
40
|
+
For React 18 and above projects, changing the value of `ssr.mode` from `'stream'` to `'string'` has no impact on the rendering result if you don't modify the code in Data Loader or use Suspense. If your project depends on React 17, please manually set the value of `ssr.mode` to `'string'`.
|
|
41
|
+
|
|
42
|
+
## Using React Router v7
|
|
43
|
+
|
|
44
|
+
Modern.js 3.0 uses React Router v7 as the default routing library. React Router v7 has only a few [incompatible changes](https://reactrouter.com/upgrading/v6) compared to v6.
|
|
45
|
+
|
|
46
|
+
If you need to use React Router v5 or React Router v6, you need to use **self-controlled routing** mode. Self-controlled routing allows you to fully control routing configuration without being limited by Modern.js convention-based routing.
|
|
47
|
+
|
|
48
|
+
## Using @modern-js/create to Create Monorepo and Modern.js Module
|
|
49
|
+
|
|
50
|
+
Modern.js 3.0 no longer supports creating Monorepo projects and Modern.js Module projects through `@modern-js/create`.
|
|
51
|
+
|
|
52
|
+
**Changes**:
|
|
53
|
+
|
|
54
|
+
- In [v2.53.0](https://github.com/web-infra-dev/modern.js/releases/tag/v2.53.0), the functionality to create Monorepo projects using `@modern-js/create` was removed
|
|
55
|
+
- In [v2.61.0](https://github.com/web-infra-dev/modern.js/releases/tag/v2.61.0), the functionality to create Modern.js Module projects using `@modern-js/create` and `modern new` commands was removed
|
|
56
|
+
|
|
57
|
+
**Handling**:
|
|
58
|
+
|
|
59
|
+
- **Monorepo Projects**: The Monorepo solution previously provided by Modern.js was based on [pnpm Workspace](https://pnpm.io/workspaces) and did not provide substantial Monorepo management capabilities. It is recommended to directly use community-provided Monorepo solutions such as [Turborepo](https://turbo.build/), [Nx](https://nx.dev/), etc.
|
|
60
|
+
- **Modern.js Module Projects**: It is recommended to use [Rslib](https://rslib.rs/) to create and manage JavaScript library and UI component projects. Rslib is a library development tool based on Rsbuild, providing a simple and intuitive way to create JavaScript libraries. For detailed usage, please refer to the [Rslib official documentation](https://rslib.rs/).
|
|
61
|
+
|
|
62
|
+
## new and upgrade Commands Removed
|
|
63
|
+
|
|
64
|
+
Modern.js 3.0 removed the `modern new` and `modern upgrade` commands, and you need to perform operations manually according to the documentation.
|
|
65
|
+
|
|
66
|
+
**Changes**:
|
|
67
|
+
|
|
68
|
+
- The `modern new` command is no longer supported in Modern.js 3.0, and you cannot add entries or enable features through commands
|
|
69
|
+
- The `modern upgrade` command is no longer supported in Modern.js 3.0, and you cannot automatically upgrade dependencies through commands
|
|
70
|
+
|
|
71
|
+
**Handling**:
|
|
72
|
+
|
|
73
|
+
- **Adding Entries**: You need to manually create entry directories and files according to the documentation. For detailed steps, please refer to the [Page Entries documentation](/guides/concept/entries).
|
|
74
|
+
- **Enabling Features**: You need to manually install dependencies and configure according to the corresponding feature documentation. For example, to enable BFF functionality, you need to install the `@modern-js/plugin-bff` plugin and configure it in `modern.config.ts`.
|
|
75
|
+
- **Upgrading Dependencies**: You need to manually update the versions of all `@modern-js/**` packages in `package.json`, then reinstall dependencies. For detailed steps, please refer to the [Version Upgrade documentation](/guides/get-started/upgrade).
|
|
76
|
+
|
|
77
|
+
:::info Note
|
|
78
|
+
The purpose of removing these commands is to make the documentation more aligned with the default implementation approach of AI Agents, not encapsulating operations, so that developers can more clearly understand the specific steps of each operation, and it is also convenient for AI Agents to directly execute corresponding operations according to the documentation.
|
|
79
|
+
:::
|
|
80
|
+
|
|
81
|
+
## ESLint Rule Sets
|
|
82
|
+
|
|
83
|
+
Modern.js previously provided complete ESLint rule sets, covering @modern-js (Lint rules for Node.js projects) and @modern-js-app (Lint rules for frontend projects). In [v2.60.0](https://github.com/web-infra-dev/modern.js/releases/tag/v2.60.0), we officially removed these rule sets. We encourage developers to choose appropriate code specification tools according to their needs, directly use ESLint combined with community-recommended rules, or use Biome to improve code formatting performance.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Overview
|
|
2
|
+
|
|
3
|
+
This guide will help you upgrade from Modern.js 2.0 to Modern.js 3.0.
|
|
4
|
+
|
|
5
|
+
## Upgrade Overview
|
|
6
|
+
|
|
7
|
+
Modern.js 3.0 brings significant improvements and changes, including:
|
|
8
|
+
|
|
9
|
+
- **Build Tool Upgrade**: Default use of [Rspack](https://rspack.dev) for building, no longer supporting Webpack. Build configuration is aligned with [Rsbuild](https://rsbuild.dev).
|
|
10
|
+
- **React Ecosystem Upgrade**: Full support for [React 19](https://react.dev/blog/2024/04/25/react-19) and [React Router v7](https://reactrouter.com).
|
|
11
|
+
- **Plugin System Refactoring**: Redesigned plugin API, supporting custom plugins at CLI, Runtime, and Server layers to extend framework capabilities.
|
|
12
|
+
- **React Server Component**: Support for using React Server Component in [CSR](/guides/get-started/glossary#csr) and [SSR](/guides/basic-features/render/ssr) projects.
|
|
13
|
+
- **Internationalization Enhancement**: Provides out-of-the-box [i18n plugin](/guides/advanced-features/international) to simplify internationalization development workflow.
|
|
14
|
+
- **SSG Capability Improvement**: Provides complete [Static Site Generation (SSG)](/guides/basic-features/render/ssg) support.
|
|
15
|
+
- **Route Configuration Enhancement**: Supports [config-based routing](/guides/basic-features/routes/config-routes), which can be used alone or combined with [convention-based routing](/guides/basic-features/routes/routes), providing more flexible route definition.
|
|
16
|
+
|
|
17
|
+
## Pre-upgrade Checklist
|
|
18
|
+
|
|
19
|
+
Before starting the upgrade, please confirm:
|
|
20
|
+
|
|
21
|
+
1. Your current project is using Modern.js 2.0
|
|
22
|
+
2. The React version is 17 or higher
|
|
23
|
+
3. The Node.js version is 18.20.8 or higher. We recommend using Node.js 22 or higher
|
|
24
|
+
|
|
25
|
+
## Getting Help
|
|
26
|
+
|
|
27
|
+
If you encounter any issues during the upgrade process, you can get help through the following channels:
|
|
28
|
+
|
|
29
|
+
- Check the [Modern.js official documentation](https://modernjs.dev)
|
|
30
|
+
- Search for related issues or submit a new issue in [GitHub Issues](https://github.com/web-infra-dev/modern.js/issues)
|
|
31
|
+
- Join the [Modern.js Discord community](https://discord.gg/modernjs) to communicate with other developers
|
|
32
|
+
|
|
33
|
+
We recommend providing as much detail as possible when submitting an issue, including error logs, configuration files, and reproduction steps, to help resolve issues faster.
|