@modern-js/main-doc 2.12.0 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +15 -0
- package/docs/en/apis/app/commands.mdx +1 -1
- package/docs/en/apis/app/hooks/api/framework/lambda.mdx +2 -2
- package/docs/en/apis/app/hooks/api/functions/api.mdx +3 -3
- package/docs/en/apis/app/hooks/api/functions/app.mdx +1 -1
- package/docs/en/apis/app/hooks/api/test.mdx +2 -1
- package/docs/en/apis/app/hooks/config/mock.mdx +1 -1
- package/docs/en/apis/app/hooks/config/upload.mdx +1 -1
- package/docs/en/apis/app/hooks/server/test.mdx +1 -1
- package/docs/en/apis/app/hooks/src/app.mdx +1 -1
- package/docs/en/apis/app/hooks/src/pages.mdx +1 -1
- package/docs/en/apis/app/runtime/app/define-config.mdx +1 -1
- package/docs/en/apis/app/runtime/core/bootstrap.mdx +2 -2
- package/docs/en/apis/app/runtime/core/use-loader.mdx +6 -2
- package/docs/en/apis/app/runtime/model/auto-actions.mdx +6 -6
- package/docs/en/apis/app/runtime/model/connect.mdx +2 -1
- package/docs/en/apis/app/runtime/model/create-app.mdx +1 -1
- package/docs/en/apis/app/runtime/model/handle-effect.mdx +3 -3
- package/docs/en/apis/app/runtime/model/model_.mdx +2 -2
- package/docs/en/apis/app/runtime/model/use-model.mdx +2 -2
- package/docs/en/apis/app/runtime/model/use-static-model.mdx +2 -2
- package/docs/en/apis/app/runtime/model/use-store.mdx +1 -1
- package/docs/en/apis/app/runtime/router/router.mdx +1 -0
- package/docs/en/apis/app/runtime/ssr/pre-render.mdx +2 -2
- package/docs/en/apis/app/runtime/testing/render.mdx +1 -1
- package/docs/en/components/enable-bff.mdx +2 -2
- package/docs/en/configure/app/html/script-loading.mdx +13 -0
- package/docs/en/configure/app/output/ssg.mdx +1 -1
- package/docs/en/configure/app/plugins.mdx +3 -3
- package/docs/en/configure/app/source/disable-entry-dirs.mdx +1 -1
- package/docs/en/configure/app/tools/swc.mdx +1 -1
- package/docs/en/configure/app/usage.mdx +65 -23
- package/docs/en/guides/advanced-features/bff/function.mdx +3 -3
- package/docs/en/guides/advanced-features/code-split.mdx +2 -2
- package/docs/en/guides/advanced-features/eslint.mdx +1 -1
- package/docs/en/guides/advanced-features/ssg.mdx +2 -2
- package/docs/en/guides/advanced-features/ssr.mdx +45 -8
- package/docs/en/guides/basic-features/alias.mdx +1 -1
- package/docs/en/guides/basic-features/env-vars.mdx +5 -5
- package/docs/en/guides/basic-features/html.mdx +0 -4
- package/docs/en/guides/basic-features/routes.mdx +48 -28
- package/docs/en/guides/concept/entries.mdx +3 -3
- package/docs/en/guides/get-started/introduction.mdx +21 -1
- package/docs/en/guides/get-started/quick-start.mdx +6 -23
- package/docs/en/guides/get-started/upgrade.mdx +7 -7
- package/docs/en/guides/topic-detail/framework-plugin/hook.mdx +1 -1
- package/docs/en/guides/topic-detail/generator/codesmith/api/json.mdx +3 -3
- package/docs/en/guides/topic-detail/generator/config/app.mdx +1 -1
- package/docs/en/guides/topic-detail/generator/config/monorepo.mdx +1 -1
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +1 -1
- package/docs/en/guides/topic-detail/model/manage-effects.mdx +2 -1
- package/docs/en/guides/topic-detail/model/model-communicate.mdx +1 -1
- package/docs/en/tutorials/foundations/introduction.mdx +0 -2
- package/docs/zh/apis/app/hooks/src/pages.mdx +1 -1
- package/docs/zh/apis/app/runtime/core/use-loader.mdx +4 -0
- package/docs/zh/apis/app/runtime/model/handle-effect.mdx +2 -1
- package/docs/zh/apis/app/runtime/model/model_.mdx +4 -2
- package/docs/zh/blog/updates/2022-0708-updates.md +1 -2
- package/docs/zh/components/enable-bff.mdx +2 -2
- package/docs/zh/configure/app/html/script-loading.mdx +13 -0
- package/docs/zh/configure/app/source/disable-entry-dirs.mdx +2 -2
- package/docs/zh/configure/app/usage.mdx +66 -24
- package/docs/zh/guides/advanced-features/ssr.mdx +74 -36
- package/docs/zh/guides/basic-features/html.mdx +0 -4
- package/docs/zh/guides/basic-features/routes.mdx +64 -24
- package/docs/zh/guides/concept/entries.mdx +4 -4
- package/docs/zh/guides/get-started/introduction.mdx +21 -1
- package/docs/zh/guides/get-started/upgrade.mdx +3 -3
- package/docs/zh/guides/topic-detail/changesets/release.mdx +2 -2
- package/package.json +5 -5
- package/src/components/SolutionCards/index.module.scss +62 -0
- package/src/components/SolutionCards/index.tsx +26 -0
@@ -13,7 +13,7 @@ First need to execute `pnpm run new` to enable the SSG features:
|
|
13
13
|
? Enable features Enable SSG
|
14
14
|
```
|
15
15
|
|
16
|
-
After execute script
|
16
|
+
After execute script, register SSG plugin in `modern.config.ts`:
|
17
17
|
|
18
18
|
```ts title="modern.config.ts"
|
19
19
|
import ssgPlugin from '@modern-js/plugin-ssg';
|
@@ -106,7 +106,7 @@ export default defineConfig({
|
|
106
106
|
});
|
107
107
|
```
|
108
108
|
|
109
|
-
run `pnpm run build` and `pnpm run serve
|
109
|
+
run `pnpm run build` and `pnpm run serve`, access `http://localhost:8080/about`. In the Preview view, you can see that the page has been rendered.
|
110
110
|
|
111
111
|
Looking at the bundle file, a new `main/about/index.html` file has been added in the `dist/` directory.
|
112
112
|
|
@@ -246,6 +246,21 @@ if (process.env.MODERN_TARGET === 'browser') {
|
|
246
246
|
}
|
247
247
|
```
|
248
248
|
|
249
|
+
After packaging in the development environment, SSR and CSR artifacts will be compiled into the following content. Therefore, there will be no more errors due to Web API in the SSR environment:
|
250
|
+
|
251
|
+
```ts
|
252
|
+
// SSR production
|
253
|
+
if (false) {
|
254
|
+
}
|
255
|
+
|
256
|
+
// CSR production
|
257
|
+
if (true) {
|
258
|
+
document.addEventListener('load', () => {
|
259
|
+
console.log('document load');
|
260
|
+
});
|
261
|
+
}
|
262
|
+
```
|
263
|
+
|
249
264
|
:::note
|
250
265
|
For more information, see [environment variables](/guides/basic-features/env-vars).
|
251
266
|
|
@@ -253,7 +268,9 @@ For more information, see [environment variables](/guides/basic-features/env-var
|
|
253
268
|
|
254
269
|
### Use File Suffix
|
255
270
|
|
256
|
-
|
271
|
+
However, in the second case, for example, when `fs-extra` is imported into the code, it internally uses the Node API with side effects. If it is directly referenced in the component, it will cause CSR loading errors.
|
272
|
+
|
273
|
+
Env vars is not effective in this situation. Modern.js also supports distinguishing SSR Bundle and CSR Bundle packaging files through files with the `.node.` suffix.
|
257
274
|
|
258
275
|
For example, the import of `fs-extra` in the code, when it is directly referenced to the component, will cause the CSR to load an error. You can create `.ts` and `.node.ts` files of the same name as a layer of proxy:
|
259
276
|
|
@@ -280,7 +297,27 @@ export const loader = () => {
|
|
280
297
|
|
281
298
|
### Independent File
|
282
299
|
|
283
|
-
Both of the above methods
|
300
|
+
Both of the above methods can bring some mental burden to developers. In real business scenarios, we found that most of the mixed Node/Web code occurs in data requests.
|
301
|
+
|
302
|
+
Therefore, Modern.js developed a [Data Fetch](/guides/basic-features/data-fetch) to separate CSR and SSR code based on [Nested Routing](/guides/basic-features/routes).
|
303
|
+
|
304
|
+
We can separate **data request** and **component code** by using independent files. Write component logic in `routes/page.tsx` and data request logic in `routes/page.loader.ts`.
|
305
|
+
|
306
|
+
```ts title="routes/page.tsx"
|
307
|
+
export default Page = () => {
|
308
|
+
return <div>Hello World<div>
|
309
|
+
}
|
310
|
+
```
|
311
|
+
|
312
|
+
```ts title="routes/page.loader.tsx"
|
313
|
+
import fse from 'fs-extra';
|
314
|
+
export default () => {
|
315
|
+
const file = fse.readFileSync('./myfile');
|
316
|
+
return {
|
317
|
+
...
|
318
|
+
};
|
319
|
+
}
|
320
|
+
```
|
284
321
|
|
285
322
|
## Remote Request
|
286
323
|
|
@@ -317,7 +354,7 @@ The streaming SSR of Modern.js is implemented based on React Router, and the mai
|
|
317
354
|
|
318
355
|
### Return async data
|
319
356
|
|
320
|
-
```ts title=
|
357
|
+
```ts title="page.loader.ts"
|
321
358
|
import { defer, type LoaderFunctionArgs } from '@modern-js/runtime/router';
|
322
359
|
|
323
360
|
interface User {
|
@@ -351,7 +388,7 @@ therefore, the parameter passed to `defer` is `{data: user}`.
|
|
351
388
|
|
352
389
|
`defer` can also receive asynchronous data and synchronous data at the same time. For example:
|
353
390
|
|
354
|
-
```ts title=
|
391
|
+
```ts title="page.loader.ts"
|
355
392
|
|
356
393
|
// skip some codes
|
357
394
|
|
@@ -388,7 +425,7 @@ export default ({ params }: LoaderFunctionArgs) => {
|
|
388
425
|
|
389
426
|
Use the `Await` component to render the data returned asynchronously from the Data Loader. For example:
|
390
427
|
|
391
|
-
```tsx title=
|
428
|
+
```tsx title="page.tsx"
|
392
429
|
import { Await, useLoaderData } from '@modern-js/runtime/router';
|
393
430
|
import { Suspense } from 'react';
|
394
431
|
import type { Data } from './page.loader';
|
@@ -430,7 +467,7 @@ So, here we import like this: `import type { Data } from './page.loader'`;
|
|
430
467
|
|
431
468
|
You can also get the asynchronous data returned by Data Loader through `useAsyncValue`. For example:
|
432
469
|
|
433
|
-
```tsx title=
|
470
|
+
```tsx title="page.tsx"
|
434
471
|
import { useAsyncValue } from '@modern-js/runtime/router';
|
435
472
|
|
436
473
|
// skip some codes
|
@@ -468,7 +505,7 @@ export default Page;
|
|
468
505
|
The `errorElement` property of the `Await` component can be used to handle errors thrown when the Data Loader executes or when a child component renders.
|
469
506
|
For example, we intentionally throw an error in the Data Loader function:
|
470
507
|
|
471
|
-
```ts title=
|
508
|
+
```ts title="page.loader.ts"
|
472
509
|
import { defer } from '@modern-js/runtime/router';
|
473
510
|
|
474
511
|
export default () => {
|
@@ -484,7 +521,7 @@ export default () => {
|
|
484
521
|
|
485
522
|
Then use `useAsyncError` to get the error, and assign the component used to render the error to the `errorElement` property of the `Await` component:
|
486
523
|
|
487
|
-
```tsx title=
|
524
|
+
```tsx title="page.ts"
|
488
525
|
import { Await, useAsyncError, useLoaderData } from '@modern-js/runtime/router';
|
489
526
|
import { Suspense } from 'react';
|
490
527
|
|
@@ -6,7 +6,7 @@ sidebar_position: 7
|
|
6
6
|
|
7
7
|
Modern.js provides support for environment variables, including built-in environment variables and custom environment variables.
|
8
8
|
|
9
|
-
## Built-in Environment
|
9
|
+
## Built-in Environment Variables
|
10
10
|
|
11
11
|
### ASSET_PREFIX
|
12
12
|
|
@@ -31,7 +31,7 @@ MODERN_ENV priority is higher than NODE_ENV.
|
|
31
31
|
|
32
32
|
### MODERN_TARGET
|
33
33
|
|
34
|
-
Auto inject when use `@modern-js/runtime
|
34
|
+
Auto inject when use `@modern-js/runtime`, Used to distinguish between SSR and CSR environments. Developers can judge by themselves in the code, and dead code will be removed by default when building.
|
35
35
|
|
36
36
|
```ts title="App.tsx"
|
37
37
|
function App() {
|
@@ -93,7 +93,7 @@ The `.env` file follows the following loading rules:
|
|
93
93
|
|
94
94
|
When you need to use different config according to the environment, you can define environment variables in the `.env` file corresponding to the environment name, and manually set the execution environment when starting the project.
|
95
95
|
|
96
|
-
For example, when starting a project with the following command
|
96
|
+
For example, when starting a project with the following command, the `.env` and `.env.staging` will load:
|
97
97
|
|
98
98
|
```shell
|
99
99
|
MODERN_ENV=staging pnpm run dev
|
@@ -129,7 +129,7 @@ In custom HTML templates, you can also use such environment variables directly.
|
|
129
129
|
|
130
130
|
### Any Other Names
|
131
131
|
|
132
|
-
If you need to use environment variables with any other names in your code
|
132
|
+
If you need to use environment variables with any other names in your code, you can config [`source.globalVars`](/configure/app/source/global-vars), for example:
|
133
133
|
|
134
134
|
```ts title="modern.config.ts"
|
135
135
|
export default defineConfig({
|
@@ -171,4 +171,4 @@ const foo = TWO;
|
|
171
171
|
const foo = 1 + 1;
|
172
172
|
```
|
173
173
|
|
174
|
-
In most cases, `source.globalVars` is already sufficient to replace variables. But the values passed in by `source.globalVars` will be serialized by JSON by default. So it cannot be replaced like `1 + 1` in the example above
|
174
|
+
In most cases, `source.globalVars` is already sufficient to replace variables. But the values passed in by `source.globalVars` will be serialized by JSON by default. So it cannot be replaced like `1 + 1` in the example above, at this time, we need use [`source.define`](/configure/app/source/define).
|
@@ -173,10 +173,6 @@ In the application root directory, create the `config/html/` directory, which su
|
|
173
173
|
<%= meta %>
|
174
174
|
<title><%= title %></title>
|
175
175
|
<%= topTemplate %>
|
176
|
-
|
177
|
-
<script>
|
178
|
-
window.__assetPrefix__ = '<%= assetPrefix %>';
|
179
|
-
</script>
|
180
176
|
<%= headTemplate %>
|
181
177
|
{/* webpack inject css */}
|
182
178
|
</head>
|
@@ -2,6 +2,7 @@
|
|
2
2
|
title: Routes
|
3
3
|
sidebar_position: 1
|
4
4
|
---
|
5
|
+
|
5
6
|
# Routes
|
6
7
|
|
7
8
|
Modern.js build-in provides partial support for [React Router 6](https://reactrouter.com/en/main) and provides various types of routing modes. According to different [entry](/guides/concept/entries) types, routing is divided into three modes, namely **Conventional routing**, **Self-controlled routing** and **Other**.
|
@@ -57,8 +58,8 @@ Similarly, `routes/user/layout.tsx` will be used as a layout component for all c
|
|
57
58
|
```tsx
|
58
59
|
<Layout>
|
59
60
|
<UserLayout>
|
60
|
-
<UserPage
|
61
|
-
|
61
|
+
<UserPage />
|
62
|
+
</UserLayout>
|
62
63
|
</Layout>
|
63
64
|
```
|
64
65
|
|
@@ -106,8 +107,8 @@ In order to facilitate the introduction of the relationship between `<Layout>` a
|
|
106
107
|
```tsx
|
107
108
|
<Layout>
|
108
109
|
<UserLayout>
|
109
|
-
<UserPage
|
110
|
-
|
110
|
+
<UserPage />
|
111
|
+
</UserLayout>
|
111
112
|
</Layout>
|
112
113
|
```
|
113
114
|
|
@@ -158,10 +159,9 @@ The `routes/$.tsx` component is rendered when accessing any path that does not m
|
|
158
159
|
import { useParams } from '@modern-js/runtime/router';
|
159
160
|
// When the path is `/aaa/bbb`
|
160
161
|
const params = useParams();
|
161
|
-
params['*']
|
162
|
+
params['*']; // => 'aaa/bbb'
|
162
163
|
```
|
163
164
|
|
164
|
-
|
165
165
|
### Layout with No Path
|
166
166
|
|
167
167
|
When a directory name begins with `__`, the corresponding directory name is not converted to the actual routing path, such as the following file directory:
|
@@ -230,15 +230,15 @@ When a route jumps from `/` to `/blog`, if the JS Chunk of the `<Blog>` componen
|
|
230
230
|
You can redirect routes by creating a [`data loader`](/guides/basic-features/data-fetch) file, Suppose you have the file `routes/user/page.tsx` and you want to redirect the route corresponding to this file, you can create the file `routes/user/page.loader.ts`:
|
231
231
|
|
232
232
|
```ts title="routes/user/page.loader.ts"
|
233
|
-
import { redirect } from '@modern-js/runtime/router'
|
233
|
+
import { redirect } from '@modern-js/runtime/router';
|
234
234
|
|
235
235
|
export default () => {
|
236
236
|
const user = await getUser();
|
237
|
-
if(!user){
|
237
|
+
if (!user) {
|
238
238
|
return redirect('/login');
|
239
239
|
}
|
240
240
|
return null;
|
241
|
-
}
|
241
|
+
};
|
242
242
|
```
|
243
243
|
|
244
244
|
### ErrorBoundary
|
@@ -255,15 +255,15 @@ Within the `<ErrorBoundary>` component, you can use [useRouteError](/apis/app/ru
|
|
255
255
|
|
256
256
|
```tsx
|
257
257
|
import { useRouteError } from '@modern-js/runtime/router';
|
258
|
-
export
|
258
|
+
export const ErrorBoundary = () => {
|
259
259
|
const error = useRouteError();
|
260
260
|
return (
|
261
261
|
<div>
|
262
|
-
|
263
|
-
|
262
|
+
<h1>{error.status}</h1>
|
263
|
+
<h2>{error.message}</h2>
|
264
264
|
</div>
|
265
|
-
)
|
266
|
-
}
|
265
|
+
);
|
266
|
+
};
|
267
267
|
```
|
268
268
|
|
269
269
|
### Hooks before rendering
|
@@ -286,15 +286,13 @@ This feature is useful when the application requires pre-page data, custom data
|
|
286
286
|
:::
|
287
287
|
|
288
288
|
```ts title="src/routes/layout.tsx"
|
289
|
-
import {
|
290
|
-
RuntimeContext,
|
291
|
-
} from '@modern-js/runtime';
|
289
|
+
import { RuntimeContext } from '@modern-js/runtime';
|
292
290
|
|
293
291
|
export const init = (context: RuntimeContext) => {
|
294
292
|
return {
|
295
293
|
message: 'Hello World',
|
296
|
-
}
|
297
|
-
}
|
294
|
+
};
|
295
|
+
};
|
298
296
|
```
|
299
297
|
|
300
298
|
```tsx title="src/routes/page.tsx"
|
@@ -305,7 +303,7 @@ export default () => {
|
|
305
303
|
const { message } = context.getInitData();
|
306
304
|
|
307
305
|
return <div>{message}</div>;
|
308
|
-
}
|
306
|
+
};
|
309
307
|
```
|
310
308
|
|
311
309
|
When working with SSR, the browser side can get the data returned by `init` during SSR, and the developer can decide whether to retrieve the data on the browser side to overwrite the SSR data, for example:
|
@@ -317,18 +315,18 @@ export const init = (context: RuntimeContext) => {
|
|
317
315
|
if (process.env.MODERN_TARGET === 'node') {
|
318
316
|
return {
|
319
317
|
message: 'Hello World By Server',
|
320
|
-
}
|
318
|
+
};
|
321
319
|
} else {
|
322
320
|
const { context } = runtimeContext;
|
323
321
|
const data = context.getInitData();
|
324
322
|
// If do not get the expected data
|
325
323
|
if (!data.message) {
|
326
324
|
return {
|
327
|
-
message: 'Hello World By Client'
|
328
|
-
}
|
325
|
+
message: 'Hello World By Client',
|
326
|
+
};
|
329
327
|
}
|
330
328
|
}
|
331
|
-
}
|
329
|
+
};
|
332
330
|
```
|
333
331
|
|
334
332
|
### Runtime Configuration
|
@@ -341,12 +339,34 @@ import type { AppConfig } from '@modern-js/runtime';
|
|
341
339
|
export const config = (): AppConfig => {
|
342
340
|
return {
|
343
341
|
router: {
|
344
|
-
supportHtml5History: false
|
345
|
-
}
|
346
|
-
}
|
342
|
+
supportHtml5History: false,
|
343
|
+
},
|
344
|
+
};
|
347
345
|
};
|
348
346
|
```
|
349
347
|
|
348
|
+
### Prefetch
|
349
|
+
|
350
|
+
When using convention-based routing, Modern.js will automatically split chunks according to the route, and when the user accesses a specific route, the corresponding resources will be loaded automatically, which can effectively reduce the first screen loading time. However, this also brings a problem, when the user accesses a route, if the asset corresponding to that route is not yet loaded, a white screen will appear.
|
351
|
+
|
352
|
+
In this case you can show a custom `loading` component by defining a `loading` component before the static resource is loaded.
|
353
|
+
|
354
|
+
To further improve the user experience and reduce time of loading, Modern.js supports defining the `prefetch` property on the Link component to load static resources and data in advance, with three optional values for the `prefetch` property:
|
355
|
+
|
356
|
+
```
|
357
|
+
<Link prefetch="intent" to="page">
|
358
|
+
```
|
359
|
+
|
360
|
+
:::info
|
361
|
+
- This feature is currently only supported in Webpack projects, not in Rspack projects.
|
362
|
+
- Prefetching of data will only prefetch the data returned from the data loader of the SSR project.
|
363
|
+
|
364
|
+
:::
|
365
|
+
|
366
|
+
- `none`, the default value, will not do prefetch, no additional behavior.
|
367
|
+
- `intent`, the value we recommend for most scenarios, will automatically start loading the corresponding resources and the data defined in the data loader when you mouse over the Link, and will automatically unload it when the mouse is moved away. In our tests, even a direct click can reduce the loading time by about 200ms.
|
368
|
+
- `render`, when the Link component renders, it will load the corresponding resources and the data defined in the data loader.
|
369
|
+
|
350
370
|
## Self-controlled routing
|
351
371
|
|
352
372
|
With `src/App.tsx` as the agreed entry, Modern.js will not do additional operations with multiple routes, developers can use the React Router 6 API for development by themselves, for example:
|
@@ -367,7 +387,7 @@ export default () => {
|
|
367
387
|
```
|
368
388
|
|
369
389
|
:::note
|
370
|
-
Modern.js has a series of resource loading and rendering optimizations to the default convention-based routing, and provides out-of-the-box SSR capabilities,
|
390
|
+
Modern.js has a series of resource loading and rendering optimizations to the default convention-based routing, and provides out-of-the-box SSR capabilities, when using self-directed routing, need to be packaged by the developer, and it is recommended that developers use convention-based routing.
|
371
391
|
|
372
392
|
:::
|
373
393
|
|
@@ -132,9 +132,9 @@ The content of the file generated by Modern.js is as follows:
|
|
132
132
|
```js
|
133
133
|
import React from 'react';
|
134
134
|
import ReactDOM from 'react-dom/client';
|
135
|
-
import customBootstrap from '@
|
136
|
-
import App from '@
|
137
|
-
import { router, state } from '@
|
135
|
+
import customBootstrap from '@_modern_js_src/index.tsx';
|
136
|
+
import App from '@_modern_js_src/App';
|
137
|
+
import { router, state } from '@modern-js/runtime/plugins';
|
138
138
|
|
139
139
|
const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
|
140
140
|
const MOUNT_ID = 'root';
|
@@ -9,7 +9,27 @@ sidebar_position: 1
|
|
9
9
|
|
10
10
|
Currently, Modern.js includes three solutions, each targeting at different development scenarios: web application development, npm package development, and document site development:
|
11
11
|
|
12
|
-
|
12
|
+
import { SolutionCards } from '@site/src/components/SolutionCards';
|
13
|
+
|
14
|
+
<SolutionCards
|
15
|
+
cards={[
|
16
|
+
{
|
17
|
+
title: 'Modern.js Framework',
|
18
|
+
description: 'For web application development',
|
19
|
+
link: 'http://modernjs.dev/en/',
|
20
|
+
},
|
21
|
+
{
|
22
|
+
title: 'Modern.js Module',
|
23
|
+
description: 'For npm package development',
|
24
|
+
link: 'http://modernjs.dev/module-tools/en/',
|
25
|
+
},
|
26
|
+
{
|
27
|
+
title: 'Modern.js Doc',
|
28
|
+
description: 'For document site development',
|
29
|
+
link: 'http://modernjs.dev/doc-tools/',
|
30
|
+
},
|
31
|
+
]}
|
32
|
+
/>
|
13
33
|
|
14
34
|
As a part of the Modern.js engineering system, each of these solutions can be used separately and has its own independent documentation site. Developers can choose one or more solutions as needed.
|
15
35
|
|
@@ -7,39 +7,22 @@ sidebar_position: 2
|
|
7
7
|
|
8
8
|
## Environment
|
9
9
|
|
10
|
-
|
10
|
+
import Prerequisites from "@site-docs-en/components/prerequisites"
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
Modern.js recommend installing [nvm](https://github.com/nvm-sh/nvm#install--update-script) in the development environment and integrating [script to automatically switch node versions](https://github.com/nvm-sh/nvm#deeper-shell-integration) in the shell.
|
15
|
-
|
16
|
-
Then there is a `.nvmrc` file with the content of `lts/fermium` or `lts/gallium` in the root directory of the repository, it will automatically install or switch to the correct Node.js version when entering the repository.
|
17
|
-
|
18
|
-
### pnpm
|
19
|
-
|
20
|
-
[pnpm](https://pnpm.io/installation) is recommended for package management.
|
21
|
-
|
22
|
-
```bash
|
23
|
-
npm install -g pnpm@7
|
24
|
-
```
|
25
|
-
|
26
|
-
:::note
|
27
|
-
Modern.js also supports other package managers, such as `yarn` or `npm`.
|
28
|
-
|
29
|
-
:::
|
12
|
+
<Prerequisites />
|
30
13
|
|
31
14
|
## Installation
|
32
15
|
|
33
|
-
Modern.js provides the `@modern-js/create` tool
|
16
|
+
Modern.js provides the `@modern-js/create` tool for creating new projects. You can use `npx` to run it.
|
34
17
|
|
35
|
-
|
18
|
+
You can create the project in an existing empty directory:
|
36
19
|
|
37
20
|
```bash
|
38
21
|
mkdir myapp && cd myapp
|
39
22
|
npx @modern-js/create
|
40
23
|
```
|
41
24
|
|
42
|
-
|
25
|
+
You can also directly create the project as a new folder:
|
43
26
|
|
44
27
|
```bash
|
45
28
|
npx @modern-js/create myapp
|
@@ -161,4 +144,4 @@ Open http://localhost:8000/ in the browser and the content should be the same as
|
|
161
144
|
|
162
145
|
## Deploy
|
163
146
|
|
164
|
-
|
147
|
+
Once the local verification is complete, the outputs under `dist` folder can be organized into the structure required by the server for deployment.
|
@@ -25,24 +25,24 @@ You can see that the dependency in the project `package.json` has been changed t
|
|
25
25
|
|
26
26
|
## Specify version upgrade
|
27
27
|
|
28
|
-
Modern.js
|
28
|
+
All packages of Modern.js are published using the **unified version number**.
|
29
29
|
|
30
|
-
According to the website
|
30
|
+
According to the website release note, developers can also manually upgrade the project to the desired version.
|
31
31
|
|
32
32
|
:::tip
|
33
33
|
When upgrading, you need to upgrade to all packages provided by the Modern.js, rather than upgrading a single dependency.
|
34
34
|
|
35
35
|
:::
|
36
36
|
|
37
|
-
##
|
37
|
+
## Lock nested dependency
|
38
38
|
|
39
|
-
When there is a problem with one of the
|
39
|
+
When there is a problem with one of the nested dependencies of the project, and the Modern.js cannot be updated immediately, you can use the package manager to lock the child dependency version.
|
40
40
|
|
41
41
|
### pnpm
|
42
42
|
|
43
43
|
For projects using pnpm, add the following configuration to the `package.json` in the **project root directory** and re-execute `pnpm install`:
|
44
44
|
|
45
|
-
```json
|
45
|
+
```json title="package.json"
|
46
46
|
{
|
47
47
|
"pnpm": {
|
48
48
|
"overrides": {
|
@@ -56,7 +56,7 @@ For projects using pnpm, add the following configuration to the `package.json` i
|
|
56
56
|
|
57
57
|
For projects using Yarn, add the following configuration to the `package.json` in the **project root directory** and re-execute `yarn install`:
|
58
58
|
|
59
|
-
```json
|
59
|
+
```json title="package.json"
|
60
60
|
{
|
61
61
|
"resolutions": {
|
62
62
|
"package-name": "^1.0.0"
|
@@ -68,7 +68,7 @@ For projects using Yarn, add the following configuration to the `package.json` i
|
|
68
68
|
|
69
69
|
For projects using Npm, add the following configuration to the `package.json` in the **project root directory** and re-execute `npm install`:
|
70
70
|
|
71
|
-
```json
|
71
|
+
```json title="package.json"
|
72
72
|
{
|
73
73
|
"overrides": {
|
74
74
|
"package-name": "^1.0.0"
|
@@ -32,7 +32,7 @@ pipeline.run(1); // 4
|
|
32
32
|
pipeline.run(5); // 12
|
33
33
|
```
|
34
34
|
|
35
|
-
In this example, a `Pipeline<number, number>` is created on line 3. This means that when you run it, you need to pass in a `number`, and you will get a `number` as a result
|
35
|
+
In this example, a `Pipeline<number, number>` is created on line 3. This means that when you run it, you need to pass in a `number`, and you will get a `number` as a result, the type is:
|
36
36
|
|
37
37
|
```ts
|
38
38
|
(count: number, next: (nextCount: number) => number) => number;
|
@@ -35,7 +35,7 @@ Get the JSON file content.
|
|
35
35
|
|
36
36
|
Parameter:
|
37
37
|
|
38
|
-
- resource: `FsResource`. A file resource
|
38
|
+
- resource: `FsResource`. A file resource, get by `context.materials.default.get(<filename>)`.
|
39
39
|
|
40
40
|
### extend
|
41
41
|
|
@@ -43,7 +43,7 @@ Merge objects into a JSON file.
|
|
43
43
|
|
44
44
|
Parameter:
|
45
45
|
|
46
|
-
- resource: `FsResource`. A file resource
|
46
|
+
- resource: `FsResource`. A file resource, get by `context.materials.default.get(<filename>)`.
|
47
47
|
- obj: `Record<string, any>`. Object to be merged.
|
48
48
|
|
49
49
|
### update
|
@@ -52,5 +52,5 @@ pdate object fields to JSON file.
|
|
52
52
|
|
53
53
|
Parameter:
|
54
54
|
|
55
|
-
- resource: `FsResource`. A file resource
|
55
|
+
- resource: `FsResource`. A file resource, get by `context.materials.default.get(<filename>)`.
|
56
56
|
- operation: `{ query: Record<string, any>; update: Record<string, any> }`. Update operation, use gesture to view [declaration-update](https://www.npmjs.com/package/declaration-update) in detail.
|
@@ -12,7 +12,7 @@ The Monorepo project supports the creation of sub-projects by using the new comm
|
|
12
12
|
|
13
13
|
### solution
|
14
14
|
|
15
|
-
Subproject type(solution)
|
15
|
+
Subproject type(solution), the different subproject type fields are:
|
16
16
|
|
17
17
|
- Application (mwa)
|
18
18
|
- Application (Test) (mwa_test)
|
@@ -4,7 +4,7 @@ sidebar_position: 2
|
|
4
4
|
|
5
5
|
# addHelper
|
6
6
|
|
7
|
-
For text files, add a customized Help function of Handlebars
|
7
|
+
For text files, add a customized Help function of Handlebars, the specific viewable document[Custom Helpers](https://handlebarsjs.com/guide/#custom-helpers).
|
8
8
|
|
9
9
|
This method is available on the `onForged` time to live API parameter.
|
10
10
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
sidebar_position: 5
|
3
3
|
title: Management Effect
|
4
4
|
---
|
5
|
+
|
5
6
|
# Management Effect
|
6
7
|
|
7
8
|
The actions in the model must be pure functions and cannot have any side effects during execution. However, in real-world scenarios, we often encounter many side effects, such as: requesting data from an HTTP API to obtain state data, or modifying `localStorage` or sending events while updating the state. In Reduck, side effects are managed through the model's `effects` function.
|
@@ -88,7 +89,7 @@ For this type of side effect scenario, `handleEffect` stipulates that the state
|
|
88
89
|
{
|
89
90
|
result: null,
|
90
91
|
error: null,
|
91
|
-
pending: false
|
92
|
+
pending: false,
|
92
93
|
}
|
93
94
|
```
|
94
95
|
|
@@ -85,7 +85,7 @@ pages 目录下的文件满足以下条件的不会被当做路由文件
|
|
85
85
|
import React from 'react';
|
86
86
|
import UserLayout from 'xxxx';
|
87
87
|
|
88
|
-
export
|
88
|
+
export const App = ({Component, ...pageProps}:{ Component: React.ComponentType}) => {
|
89
89
|
return (
|
90
90
|
<UserLayout>
|
91
91
|
<Component {...pageProps} />
|