@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.
Files changed (72) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/docs/en/apis/app/commands.mdx +1 -1
  3. package/docs/en/apis/app/hooks/api/framework/lambda.mdx +2 -2
  4. package/docs/en/apis/app/hooks/api/functions/api.mdx +3 -3
  5. package/docs/en/apis/app/hooks/api/functions/app.mdx +1 -1
  6. package/docs/en/apis/app/hooks/api/test.mdx +2 -1
  7. package/docs/en/apis/app/hooks/config/mock.mdx +1 -1
  8. package/docs/en/apis/app/hooks/config/upload.mdx +1 -1
  9. package/docs/en/apis/app/hooks/server/test.mdx +1 -1
  10. package/docs/en/apis/app/hooks/src/app.mdx +1 -1
  11. package/docs/en/apis/app/hooks/src/pages.mdx +1 -1
  12. package/docs/en/apis/app/runtime/app/define-config.mdx +1 -1
  13. package/docs/en/apis/app/runtime/core/bootstrap.mdx +2 -2
  14. package/docs/en/apis/app/runtime/core/use-loader.mdx +6 -2
  15. package/docs/en/apis/app/runtime/model/auto-actions.mdx +6 -6
  16. package/docs/en/apis/app/runtime/model/connect.mdx +2 -1
  17. package/docs/en/apis/app/runtime/model/create-app.mdx +1 -1
  18. package/docs/en/apis/app/runtime/model/handle-effect.mdx +3 -3
  19. package/docs/en/apis/app/runtime/model/model_.mdx +2 -2
  20. package/docs/en/apis/app/runtime/model/use-model.mdx +2 -2
  21. package/docs/en/apis/app/runtime/model/use-static-model.mdx +2 -2
  22. package/docs/en/apis/app/runtime/model/use-store.mdx +1 -1
  23. package/docs/en/apis/app/runtime/router/router.mdx +1 -0
  24. package/docs/en/apis/app/runtime/ssr/pre-render.mdx +2 -2
  25. package/docs/en/apis/app/runtime/testing/render.mdx +1 -1
  26. package/docs/en/components/enable-bff.mdx +2 -2
  27. package/docs/en/configure/app/html/script-loading.mdx +13 -0
  28. package/docs/en/configure/app/output/ssg.mdx +1 -1
  29. package/docs/en/configure/app/plugins.mdx +3 -3
  30. package/docs/en/configure/app/source/disable-entry-dirs.mdx +1 -1
  31. package/docs/en/configure/app/tools/swc.mdx +1 -1
  32. package/docs/en/configure/app/usage.mdx +65 -23
  33. package/docs/en/guides/advanced-features/bff/function.mdx +3 -3
  34. package/docs/en/guides/advanced-features/code-split.mdx +2 -2
  35. package/docs/en/guides/advanced-features/eslint.mdx +1 -1
  36. package/docs/en/guides/advanced-features/ssg.mdx +2 -2
  37. package/docs/en/guides/advanced-features/ssr.mdx +45 -8
  38. package/docs/en/guides/basic-features/alias.mdx +1 -1
  39. package/docs/en/guides/basic-features/env-vars.mdx +5 -5
  40. package/docs/en/guides/basic-features/html.mdx +0 -4
  41. package/docs/en/guides/basic-features/routes.mdx +48 -28
  42. package/docs/en/guides/concept/entries.mdx +3 -3
  43. package/docs/en/guides/get-started/introduction.mdx +21 -1
  44. package/docs/en/guides/get-started/quick-start.mdx +6 -23
  45. package/docs/en/guides/get-started/upgrade.mdx +7 -7
  46. package/docs/en/guides/topic-detail/framework-plugin/hook.mdx +1 -1
  47. package/docs/en/guides/topic-detail/generator/codesmith/api/json.mdx +3 -3
  48. package/docs/en/guides/topic-detail/generator/config/app.mdx +1 -1
  49. package/docs/en/guides/topic-detail/generator/config/monorepo.mdx +1 -1
  50. package/docs/en/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +1 -1
  51. package/docs/en/guides/topic-detail/model/manage-effects.mdx +2 -1
  52. package/docs/en/guides/topic-detail/model/model-communicate.mdx +1 -1
  53. package/docs/en/tutorials/foundations/introduction.mdx +0 -2
  54. package/docs/zh/apis/app/hooks/src/pages.mdx +1 -1
  55. package/docs/zh/apis/app/runtime/core/use-loader.mdx +4 -0
  56. package/docs/zh/apis/app/runtime/model/handle-effect.mdx +2 -1
  57. package/docs/zh/apis/app/runtime/model/model_.mdx +4 -2
  58. package/docs/zh/blog/updates/2022-0708-updates.md +1 -2
  59. package/docs/zh/components/enable-bff.mdx +2 -2
  60. package/docs/zh/configure/app/html/script-loading.mdx +13 -0
  61. package/docs/zh/configure/app/source/disable-entry-dirs.mdx +2 -2
  62. package/docs/zh/configure/app/usage.mdx +66 -24
  63. package/docs/zh/guides/advanced-features/ssr.mdx +74 -36
  64. package/docs/zh/guides/basic-features/html.mdx +0 -4
  65. package/docs/zh/guides/basic-features/routes.mdx +64 -24
  66. package/docs/zh/guides/concept/entries.mdx +4 -4
  67. package/docs/zh/guides/get-started/introduction.mdx +21 -1
  68. package/docs/zh/guides/get-started/upgrade.mdx +3 -3
  69. package/docs/zh/guides/topic-detail/changesets/release.mdx +2 -2
  70. package/package.json +5 -5
  71. package/src/components/SolutionCards/index.module.scss +62 -0
  72. 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 scriptregister SSG plugin in `modern.config.ts`:
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`,access `http://localhost:8080/about`. In the Preview view, you can see that the page has been rendered.
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
- In the second case, the Treeshaking method does not guarantee that the code is completely separated. Modern.js also supports the packaging file of SSR Bundle and CSR Bundle products through the file suffixed with `.node.`.
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 will bring some burden to the developer. Modern.js based on [Nested Routing](/guides/basic-features/routes) developed and designed [Data Fetch](/guides/basic-features/data-fetch) to separate CSR and SSR code.
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='page.loader.ts'
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='page.loader.ts'
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='page.tsx'
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='page.tsx'
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='page.loader.ts'
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='page.ts'
524
+ ```tsx title="page.ts"
488
525
  import { Await, useAsyncError, useLoaderData } from '@modern-js/runtime/router';
489
526
  import { Suspense } from 'react';
490
527
 
@@ -4,7 +4,7 @@ sidebar_position: 8
4
4
  ---
5
5
  # Alias
6
6
 
7
- Modern.js allow aliases in JS and CSSand the following aliases are built in:
7
+ Modern.js allow aliases in JS and CSS, and the following aliases are built in:
8
8
 
9
9
  ```js
10
10
  {
@@ -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`,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.
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 commandthe `.env` and `.env.staging` will load:
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 codeyou can config [`source.globalVars`](/configure/app/source/global-vars), for example:
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 aboveat this time, we need use [`source.define`](/configure/app/source/define).
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
- <UserLayout>
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
- <UserLayout>
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['*'] // => 'aaa/bbb'
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 default const ErrorBoundary = () => {
258
+ export const ErrorBoundary = () => {
259
259
  const error = useRouteError();
260
260
  return (
261
261
  <div>
262
- <h1>{error.status}</h1>
263
- <h2>{error.message}</h2>
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, when using self-directed routing, need to be packaged by the developer, and it is recommended that developers use convention-based routing.
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 '@_edenx_src/index.tsx';
136
- import App from '@_edenx_src/App';
137
- import { router, state } from '@edenx/runtime/plugins';
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
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/Solutions-en-0945.png)
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
- ### Node.js
10
+ import Prerequisites from "@site-docs-en/components/prerequisites"
11
11
 
12
- Requires [Node.js LTS](https://github.com/nodejs/Release) and ensures that the Node version is greater than or equal to 14.19.0, 16.x version is recommended.
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 to create projects. Don't install globally, use `npx` to run on demand.
16
+ Modern.js provides the `@modern-js/create` tool for creating new projects. You can use `npx` to run it.
34
17
 
35
- Projects can be created using an existing empty directory:
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
- Projects can also be created directly from the new directory:
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
- After the local verification is completed, the products under `dist/` can be organized into the structure required by the server for deployment.
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 all packages are published using the **unified version number**.
28
+ All packages of Modern.js are published using the **unified version number**.
29
29
 
30
- According to the website Release Note, developers can also manually upgrade the project to the desired version.
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
- ## lock child dependency
37
+ ## Lock nested dependency
38
38
 
39
- When there is a problem with one of the child dependencies of the project, and the Modern.js cannot be updated immediately, you can use the package manager to lock the child dependency version.
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 resultthe type is:
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 resourceget by `context.materials.default.get(<filename>)`.
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 resourceget by `context.materials.default.get(<filename>)`.
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 resourceget by `context.materials.default.get(<filename>)`.
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.
@@ -75,7 +75,7 @@ BFF type (bffType), supports two options:
75
75
 
76
76
  ##### framework
77
77
 
78
- BFF runtime framework (framework)supports two options:
78
+ BFF runtime framework (framework), supports two options:
79
79
 
80
80
  - Express(express)
81
81
 
@@ -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)the different subproject type fields are:
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 Handlebarsthe specific viewable document[Custom Helpers](https://handlebarsjs.com/guide/#custom-helpers).
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
 
@@ -188,7 +188,7 @@ const fooModel = model('foo').define((context, { use, onMount }) => {
188
188
  let actions;
189
189
 
190
190
  onMount(() => {
191
- // after fooModel mountedget actions
191
+ // after fooModel mounted, get actions
192
192
  [, actions] = use(fooModel);
193
193
  });
194
194
 
@@ -26,5 +26,3 @@ We have prepared a tutorial on creating a "contact list app" that you can follow
26
26
  - Container components
27
27
  - New portal
28
28
  - ...
29
-
30
- Translated with www.DeepL.com/Translator (free version)
@@ -85,7 +85,7 @@ pages 目录下的文件满足以下条件的不会被当做路由文件
85
85
  import React from 'react';
86
86
  import UserLayout from 'xxxx';
87
87
 
88
- export default const App = ({Component, ...pageProps}:{ Component: React.ComponentType}) => {
88
+ export const App = ({Component, ...pageProps}:{ Component: React.ComponentType}) => {
89
89
  return (
90
90
  <UserLayout>
91
91
  <Component {...pageProps} />
@@ -5,6 +5,10 @@ title: useLoader
5
5
 
6
6
  一个同构的 API,通常会用来做异步请求。当 SSR 的时候,服务端使用 `useLoader` 预加载数据,同时浏览器端也会复用这部分数据。
7
7
 
8
+ :::tip
9
+ 在使用 Rspack 作为打包工具时,暂不支持使用 useLoader API。
10
+ :::
11
+
8
12
  ## 使用姿势
9
13
 
10
14
  ```ts
@@ -2,9 +2,10 @@
2
2
  sidebar_position: 7
3
3
  title: handleEffect
4
4
  ---
5
+
5
6
  # handleEffect
6
7
 
7
- import ReduckTip from "@site-docs/components/reduck-tip"
8
+ import ReduckTip from '@site-docs/components/reduck-tip';
8
9
 
9
10
  <ReduckTip />
10
11