@modern-js/main-doc 0.0.0-next-1683619026219 → 0.0.0-next-1683620196025

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.
Files changed (30) hide show
  1. package/CHANGELOG.md +2 -14
  2. package/docs/en/apis/app/hooks/src/index_.mdx +1 -1
  3. package/docs/en/apis/app/runtime/core/bootstrap.mdx +1 -1
  4. package/docs/en/configure/app/output/ssg.mdx +1 -3
  5. package/docs/en/configure/app/source/enable-async-entry.mdx +2 -2
  6. package/docs/en/configure/app/source/entries.mdx +0 -2
  7. package/docs/en/configure/app/tools/tailwindcss.mdx +2 -30
  8. package/docs/en/configure/app/usage.mdx +0 -35
  9. package/docs/en/guides/advanced-features/rspack-start.mdx +3 -1
  10. package/docs/en/guides/advanced-features/ssg.mdx +1 -1
  11. package/docs/en/guides/advanced-features/testing.mdx +1 -1
  12. package/docs/en/guides/basic-features/routes.mdx +1 -4
  13. package/docs/en/guides/concept/entries.mdx +13 -35
  14. package/docs/en/guides/topic-detail/framework-plugin/hook-list.mdx +4 -4
  15. package/docs/en/guides/topic-detail/generator/plugin/api/input/type.mdx +1 -1
  16. package/docs/zh/apis/app/hooks/src/index_.mdx +1 -1
  17. package/docs/zh/apis/app/runtime/core/bootstrap.mdx +1 -1
  18. package/docs/zh/configure/app/output/ssg.mdx +1 -3
  19. package/docs/zh/configure/app/source/enable-async-entry.mdx +2 -2
  20. package/docs/zh/configure/app/source/entries.mdx +0 -2
  21. package/docs/zh/configure/app/tools/tailwindcss.mdx +3 -31
  22. package/docs/zh/configure/app/usage.mdx +0 -35
  23. package/docs/zh/guides/advanced-features/rspack-start.mdx +3 -1
  24. package/docs/zh/guides/advanced-features/ssg.mdx +1 -1
  25. package/docs/zh/guides/advanced-features/testing.mdx +1 -1
  26. package/docs/zh/guides/basic-features/routes.mdx +15 -2
  27. package/docs/zh/guides/concept/entries.mdx +21 -41
  28. package/docs/zh/guides/topic-detail/framework-plugin/hook-list.mdx +4 -4
  29. package/docs/zh/guides/topic-detail/generator/plugin/api/input/type.mdx +1 -1
  30. package/package.json +5 -5
package/CHANGELOG.md CHANGED
@@ -1,22 +1,10 @@
1
1
  # @modern-js/main-doc
2
2
 
3
- ## 0.0.0-next-1683619026219
3
+ ## 0.0.0-next-1683620196025
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - 21c87bf37e: feat: bump codesmith packages version
8
-
9
- feat: 升级 codesmith 包版本
10
-
11
- - @modern-js/builder-doc@0.0.0-next-1683619026219
12
-
13
- ## 2.18.0
14
-
15
- ### Patch Changes
16
-
17
- - d0a9bf8: chore: improve entry docs, fix ssg docs
18
- chore: 优化入口文档,修复 ssg 文档
19
- - @modern-js/builder-doc@2.18.0
7
+ - @modern-js/builder-doc@0.0.0-next-1683620196025
20
8
 
21
9
  ## 2.17.1
22
10
 
@@ -4,7 +4,7 @@ sidebar_position: 4
4
4
  ---
5
5
  # index.[tj]s
6
6
 
7
- Entry identifier if App want use custom bootstrap. In most case, [`App.[tj]sx`](/apis/app/hooks/src/app) hook file can already meet our needs.
7
+ Entry identifier if App want use custom entry. In most case, [`App.[tj]sx`](/apis/app/hooks/src/app) hook file can already meet our needs.
8
8
 
9
9
  When we need to add custom behavior before `bootstrap` or completely take over the webpack entry, we can place `index.[tj]s` in `src/` or entry directory. The following are discussed in two cases:
10
10
 
@@ -3,7 +3,7 @@ title: bootstrap
3
3
  ---
4
4
  # bootstrap
5
5
 
6
- Used to start and mount App, usually without manual calls. This API is only required when using [Custom Bootstrap](/guides/concept/entries#custom-bootstrap).
6
+ Used to start and mount App, usually without manual calls. This API is only required when using [Custom App](/guides/concept/entries#自定义-app).
7
7
 
8
8
  ## Usage
9
9
 
@@ -163,9 +163,7 @@ You can set this to disable the default behavior of a client-side route:
163
163
  ```js
164
164
  export default defineConfig({
165
165
  output: {
166
- ssg: {
167
- preventDefault: ['/user'],
168
- },
166
+ preventDefault: ['/user'],
169
167
  },
170
168
  });
171
169
  ```
@@ -33,7 +33,7 @@ Then execute the `dev` or `build` command, and you can see Modern.js automatical
33
33
  node_modules
34
34
  └─ .modern-js
35
35
  └─ main
36
- ├─ bootstrap.jsx # real entry code
36
+ ├─ bootstrap.js # real entry code
37
37
  ├─ index.js # asynchronous entry file
38
38
  └─ index.html
39
39
  ```
@@ -41,7 +41,7 @@ node_modules
41
41
  The `index.js` reads as follows:
42
42
 
43
43
  ```js
44
- import('./bootstrap.jsx');
44
+ import('./bootstrap.js');
45
45
  ```
46
46
 
47
47
  At this point, you can consume any remote modules in the current page.
@@ -13,7 +13,6 @@ type Entries = Record<
13
13
  | {
14
14
  entry: string;
15
15
  disableMount?: boolean;
16
- customBootstrap?: string;
17
16
  }
18
17
  >;
19
18
  ```
@@ -82,7 +81,6 @@ When the value is `Object`, the following properties can be configured:
82
81
 
83
82
  - `entry`: `string`, entry file path.
84
83
  - `disableMount`: `boolean = false`, turn off the entry-scanning behavior of Modern.js.
85
- - `customBootstrap`: `string = ''`, [Custom Bootstrap](/guides/concept/entries#custom-bootstrap) file path。
86
84
 
87
85
  ```ts title="modern.config.ts"
88
86
  import { defineConfig } from '@modern-js/app-tools';
@@ -24,37 +24,9 @@ const tailwind = {
24
24
  };
25
25
  ```
26
26
 
27
- ### Function Type
27
+ When the value is of type `Object`, rhe configuration corresponding to [TailwindCSS](https://tailwindcss.com/docs/configuration) is merged with the default configuration through `Object.assign`.
28
28
 
29
- When `tools.tailwindcss`'s type is Function, the default tailwindcss config will be passed in as the first parameter, the config object can be modified directly, or a value can be returned as the final result.
30
-
31
- ```ts title="modern.config.ts"
32
- export default {
33
- tools: {
34
- tailwindcss(config) {
35
- config.content.push('./some-folder/**/*.{js,ts}');
36
- },
37
- },
38
- };
39
- ```
40
-
41
- ### Object Type
42
-
43
- When `tools.tailwindcss`'s type is `Object`, the config will be shallow merged with default config by `Object.assign`.
44
-
45
- ```ts title="modern.config.ts"
46
- export default {
47
- tools: {
48
- tailwindcss: {
49
- plugins: [
50
- require('@tailwindcss/forms'),
51
- require('@tailwindcss/aspect-ratio'),
52
- require('@tailwindcss/typography'),
53
- ],
54
- },
55
- },
56
- };
57
- ```
29
+ When the value is of type `Function`, the object returned by the function is merged with the default configuration by `Object.assign`.
58
30
 
59
31
  ### Limitations
60
32
 
@@ -43,15 +43,6 @@ export default defineConfig({
43
43
  });
44
44
  ```
45
45
 
46
- When using Rspack as the bundler, due to some differences in configuration types between webpack and Rspack, you need to specify `<'rspack'>` generic type for `defineConfig`:
47
-
48
- ```diff title=modern.config.ts
49
- - export default defineConfig({
50
- + export default defineConfig<'rspack'>({
51
- //...
52
- });
53
- ```
54
-
55
46
  ### modern.config.js
56
47
 
57
48
  If you are developing a non-TypeScript project, you can use the configuration file in .js format:
@@ -251,29 +242,3 @@ const mergedConfig = {
251
242
  },
252
243
  };
253
244
  ```
254
-
255
- ## Configuration Type
256
-
257
- Modern.js exports `AppUserConfig` type, which corresponds to the type of Modern.js configuration object:
258
-
259
- ```ts title="modern.config.ts"
260
- import type { AppUserConfig } from '@modern-js/app-tools';
261
-
262
- const config: AppUserConfig = {
263
- tools: {
264
- webpack: {},
265
- },
266
- };
267
- ```
268
-
269
- When using Rspack as the bundler, due to some differences in configuration types between webpack and Rspack, you need to specify `<'rspack'>` generic type for `defineConfig`:
270
-
271
- ```ts title="modern.config.ts"
272
- import type { AppUserConfig } from '@modern-js/app-tools';
273
-
274
- const config: AppUserConfig<'rspack'> = {
275
- tools: {
276
- rspack: {},
277
- },
278
- };
279
- ```
@@ -25,8 +25,10 @@ After the project is created, you can experience the project by running `pnpm ru
25
25
  :::tip
26
26
  When using Rspack as the bundler, the following Features are temporarily unavailable as some of the capabilities are still under development and we will provide support in the future.
27
27
 
28
+ - Micro Frontend
28
29
  - Storybook Devtool
29
- - The usage of [useLoader](/guides/basic-features/data-fetch.html) in Client Side Rendering
30
+ - Server Side Rendering + Conventional Routing
31
+ - Static Site Generation + Conventional Routing
30
32
 
31
33
  :::
32
34
 
@@ -86,7 +86,7 @@ After executing `pnpm run serve` to start the project, visit the page in the Net
86
86
 
87
87
  ### Self-controlled Routing
88
88
 
89
- **Self-controlled routing** is a routing through component code, which requires the application to run to obtain accurate routing information. Therefore, the SSG function cannot be used out of the box. At this time, the user needs to inform the Modern.js framework in advance which routes need to enable the SSG.
89
+ **Self-controlled routing** is a custom routing through component code, which requires the application to run to obtain accurate routing information. Therefore, the SSG function cannot be used out of the box. At this time, the user needs to inform the Modern.js framework in advance which routes need to enable the SSG.
90
90
 
91
91
  For example, there is the following code, which contains multiple routes. When setting `output.ssg` to `true`, only the entry route '/' will be rendered by default:
92
92
 
@@ -4,7 +4,7 @@ title: Testing
4
4
  ---
5
5
  # Testing
6
6
 
7
- Modern.js integrates the testing capabilities of [Jest](https://jestjs.io/) by default.
7
+ Modern.js inherits the testing capabilities of [Jest](https://jestjs.io/) by default.
8
8
 
9
9
  First need to execute `pnpm run new` enable [unit test/integration test] features:
10
10
 
@@ -388,11 +388,8 @@ export default () => {
388
388
 
389
389
  :::note
390
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.
391
- :::
392
-
393
- use self-controller routing, if the developer turns off the [`runtime.router`](/configure/app/runtime/router) configuration and uses `react-router-dom` directly, then you need to wrap the `Provider` according to the React Router documentation.
394
391
 
395
- ```tsx title="src/App.tsx"
392
+ :::
396
393
 
397
394
  ## Other
398
395
 
@@ -98,49 +98,27 @@ Framework mode refers to the need to use the capabilities of the Modern.js frame
98
98
 
99
99
  #### Conventional Routing
100
100
 
101
- If there is a `routes/` directory in the entry, Modern.js will scan the files under `routes/` at startup, and automatically generate client-side routes (react-router) based on file conventions. For example:
101
+ If there is a `routes/` directory in the entry, Modern.js will scan the files under `routes/` at startup, and automatically generate client-side routes (react-router) based on file conventions.
102
102
 
103
- ```bash
104
- .
105
- ├── src
106
- │ └── routes
107
- │ ├── layout.tsx
108
- │ └── page.tsx
109
- ```
103
+ For details, please refer to [routing](/guides/basic-features/routes).
110
104
 
111
- For details, please refer to [routing](/guides/basic-features/routes#conventional-routing).
112
-
113
- #### Self-controlled Routing
105
+ #### Custom Routing
114
106
 
115
107
  If there is an `App.[jt]sx?` file in the entry, the developer can freely set the client route in this file, or not set the client route.
116
108
 
117
- ```tsx
118
- import { BrowserRouter, Route, Routes } from '@modern-js/runtime/router';
119
-
120
- export default () => {
121
- return (
122
- <BrowserRouter>
123
- <Routes>
124
- <Route index element={<div>index</div>} />
125
- <Route path="about" element={<div>about</div>} />
126
- </Routes>
127
- </BrowserRouter>
128
- );
129
- };
130
- ```
109
+ For details, please refer to [routing](/guides/basic-features/routes).
131
110
 
132
- For details, please refer to [routing](/guides/basic-features/routes#self-controlled-routing).
111
+ #### Custom App
133
112
 
134
- #### Custom Bootstrap
135
-
136
- If there is an `index.[jt]sx` file in the entry, and when the file defaults to exporting functions, Modern.js will pass the default bootstrap function as an imported parameter, and replace the default bootstrap with the exported function, so that developers can customize Mounting components to DOM nodes, or adding custom behavior before mounting. E.g:
113
+ If there is an `index.[jt]sx` file in the entry, and when the file exports functions by default, Modern.js will still generate the code wrapped by createApp according to the runtime settings. In the rendering process, the component wrapped by createApp is passed as a parameter to the function exported by the index file, so that developers can customize the component to be mounted on the DOM node, or add custom behavior before mounting. For example:
137
114
 
138
115
  ```tsx
139
- export default (App: React.ComponentType, bootstrap: () => void) => {
116
+ import ReactDOM from 'react-dom/client';
117
+ import { bootstrap } from '@modern-js/runtime';
118
+
119
+ export default (App: React.ComponentType) => {
140
120
  // do something before bootstrap...
141
- initSomething().then(() => {
142
- bootstrap();
143
- })
121
+ bootstrap(App, 'root', undefined, ReactDOM);
144
122
  };
145
123
  ```
146
124
 
@@ -192,9 +170,9 @@ import App from './App';
192
170
  ReactDOM.render(<App />, document.getElementById('root'));
193
171
  ```
194
172
 
195
- Modern.js **not recommended** new project to use this method, this method loses some capabilities of the framework, such as the `runtime` configuration in the **`modern.config.js` file will no longer take effect**. But this method will be very useful when the project is migrated from other frameworks to Modern.js, such as CRA, or webpack that is manually built by yourself.
173
+ Modern.js **not recommended** to use this method, this method loses some capabilities of the framework, such as the `runtime` configuration in the **`modern.config.js` file will no longer take effect**. But this method will be very useful when the project is migrated from other frameworks to Modern.js, such as CRA, or webpack that is manually built by yourself.
196
174
 
197
- ## Specify Entry Using Configuration
175
+ ## Custom Entry
198
176
 
199
177
  Most existing projects are not built according to the directory convention of Modern.js. If you want to change to the directory structure agreed by Modern.js, there will be a certain migration cost.
200
178
 
@@ -611,7 +611,7 @@ export default (): CliPlugin => ({
611
611
 
612
612
  This adds a new Script tag to the HTML template.
613
613
 
614
- {/* ## Server
614
+ <!-- ## Server
615
615
 
616
616
  :::note
617
617
  The Server plugin is currently not fully opened, and the API is not guaranteed to be stable. Use with caution.
@@ -691,7 +691,7 @@ export default (): ServerPlugin => ({
691
691
  };
692
692
  },
693
693
  });
694
- ```*/}
694
+ ``` -->
695
695
 
696
696
  ## Runtime
697
697
 
@@ -762,7 +762,7 @@ export default (): Plugin => ({
762
762
  });
763
763
  ```
764
764
 
765
- {/* ### `provide`
765
+ <!-- ### `provide`
766
766
 
767
767
  - Function: Modifies the Elements that need to be rendered.
768
768
  - Execution Stage: Rendering (SSR/CSR).
@@ -834,4 +834,4 @@ export default (): Plugin => ({
834
834
  };
835
835
  },
836
836
  });
837
- ``` */}
837
+ ``` -->
@@ -34,7 +34,7 @@ Each option supports two fields:
34
34
 
35
35
  - label: display name.
36
36
 
37
- ### x-validator
37
+ ### x-validate
38
38
 
39
39
  schema verification rules. Formily's verification method is supported here, for details, please refer to [Formily Validate](https://formilyjs.org/zh-CN/guide/advanced/validate).
40
40
 
@@ -4,7 +4,7 @@ sidebar_position: 4
4
4
  ---
5
5
  # index.[tj]s
6
6
 
7
- 应用项目入口标识。
7
+ 应用项目自定义路由入口标识。
8
8
 
9
9
  通常情况下 [`src/App.[tj]sx, src/[entry]/App.[tj]sx`](/apis/app/hooks/src/app) 钩子文件已经能满足我们的需求,当我们需要在 `bootstrap` 之前添加自定义行为或者完全接管 webpack 打包入口时,可以在 `src` 或者入口目录下放置 `index.[tj]s`。 下面有分两种情况进行讨论:
10
10
 
@@ -3,7 +3,7 @@ title: bootstrap
3
3
  ---
4
4
  # bootstrap
5
5
 
6
- 用于启动和挂载应用,通常情况下不做手动调用。只有在使用[自定义 Bootstrap](/guides/concept/entries#自定义-bootstrap) 时,才需要使用该 API。
6
+ 用于启动和挂载应用,通常情况下不做手动调用。只有在使用[自定义 App](/guides/concept/entries#自定义-app) 时,才需要使用该 API。
7
7
 
8
8
  ## 使用姿势
9
9
 
@@ -163,9 +163,7 @@ export default defineConfig({
163
163
  ```js
164
164
  export default defineConfig({
165
165
  output: {
166
- ssg: {
167
- preventDefault: ['/user'],
168
- },
166
+ preventDefault: ['/user'],
169
167
  },
170
168
  });
171
169
  ```
@@ -36,7 +36,7 @@ export default defineConfig({
36
36
  node_modules
37
37
  └─ .modern-js
38
38
  └─ main
39
- ├─ bootstrap.jsx # 真正的入口代码
39
+ ├─ bootstrap.js # 真正的入口代码
40
40
  ├─ index.js # 异步入口文件(asynchronous boundary)
41
41
  └─ index.html
42
42
  ```
@@ -44,7 +44,7 @@ node_modules
44
44
  其中 `index.js` 的内容如下:
45
45
 
46
46
  ```js
47
- import('./bootstrap.jsx');
47
+ import('./bootstrap.js');
48
48
  ```
49
49
 
50
50
  此时,就可以在当前页面中消费任意的远程模块了。
@@ -13,7 +13,6 @@ type Entries = Record<
13
13
  | {
14
14
  entry: string;
15
15
  disableMount?: boolean;
16
- customBootstrap?: string;
17
16
  }
18
17
  >;
19
18
  ```
@@ -84,7 +83,6 @@ export default defineConfig({
84
83
 
85
84
  - `entry`:`string`,入口文件路径。
86
85
  - `disableMount`:`boolean = false`,关闭 Modern.js 自动生成入口代码的行为。
87
- - `customBootstrap`: `string = ''`,指定[自定义 Bootstrap](/guides/concept/entries#自定义-bootstrap) 的文件路径。
88
86
 
89
87
  ```ts title="modern.config.ts"
90
88
  import { defineConfig } from '@modern-js/app-tools';
@@ -26,40 +26,12 @@ const tailwind = {
26
26
 
27
27
  对应 [TailwindCSS](https://tailwindcss.com/docs/configuration) 的配置。
28
28
 
29
- ### Function 类型
29
+ 当值为 `Object` 类型时,与默认配置通过 `Object.assign` 合并。
30
30
 
31
- `tools.tailwindcss` Function 类型时,默认配置会作为第一个参数传入,你可以直接修改配置对象,也可以返回一个值作为最终结果:
32
-
33
- ```ts title="modern.config.ts"
34
- export default {
35
- tools: {
36
- tailwindcss(config) {
37
- config.content.push('./some-folder/**/*.{js,ts}');
38
- },
39
- },
40
- };
41
- ```
42
-
43
- ### Object 类型
44
-
45
- 当 `tools.tailwindcss` 的值为 `Object` 类型时,会与默认配置通过 `Object.assign` 浅合并。
46
-
47
- ```ts title="modern.config.ts"
48
- export default {
49
- tools: {
50
- tailwindcss: {
51
- plugins: [
52
- require('@tailwindcss/forms'),
53
- require('@tailwindcss/aspect-ratio'),
54
- require('@tailwindcss/typography'),
55
- ],
56
- },
57
- },
58
- };
59
- ```
31
+ 当值为 `Function` 类型时,函数返回的对象与默认配置通过 `Object.assign` 合并。
60
32
 
61
33
  ### 限制
62
34
 
63
35
  注意,该配置中不允许使用 `theme` 配置项,否则会构建失败。在 Modern.js 中,请使用 [source.designSystem](/configure/app/source/design-system) 作为 `Tailwind CSS Theme` 配置。
64
36
 
65
- 其他配置的使用方式和 Tailwind CSS 一致,请参考 [tailwindcss - Configuration](https://tailwindcss.com/docs/configuration)。
37
+ 其他的使用方式和 Tailwind CSS 一致: [快速传送门](https://tailwindcss.com/docs/configuration)。
@@ -43,15 +43,6 @@ export default defineConfig({
43
43
  });
44
44
  ```
45
45
 
46
- 当你使用 Rspack 作为打包工具时,由于 webpack 和 Rspack 的配置类型存在一些差异,需要为 `defineConfig` 指定 `<'rspack'>` 泛型:
47
-
48
- ```diff title=modern.config.ts
49
- - export default defineConfig({
50
- + export default defineConfig<'rspack'>({
51
- // ...
52
- });
53
- ```
54
-
55
46
  ### modern.config.js
56
47
 
57
48
  如果你在开发一个非 TypeScript 项目,可以使用 .js 格式的配置文件:
@@ -251,29 +242,3 @@ const mergedConfig = {
251
242
  },
252
243
  };
253
244
  ```
254
-
255
- ## 配置类型定义
256
-
257
- Modern.js 导出了 `AppUserConfig` 类型,对应 Modern.js 配置对象的类型:
258
-
259
- ```ts title="modern.config.ts"
260
- import type { AppUserConfig } from '@modern-js/app-tools';
261
-
262
- const config: AppUserConfig = {
263
- tools: {
264
- webpack: {},
265
- },
266
- };
267
- ```
268
-
269
- 当你使用 Rspack 作为打包工具时,由于 webpack 和 Rspack 的配置类型存在一些差异,需要为 `AppUserConfig` 指定 `<'rspack'>` 泛型:
270
-
271
- ```ts title="modern.config.ts"
272
- import type { AppUserConfig } from '@modern-js/app-tools';
273
-
274
- const config: AppUserConfig<'rspack'> = {
275
- tools: {
276
- rspack: {},
277
- },
278
- };
279
- ```
@@ -26,8 +26,10 @@ import InitRspackApp from '@site-docs/components/init-rspack-app';
26
26
  :::tip
27
27
  在使用 Rspack 作为打包工具时,由于部分能力尚在开发中,以下 features 暂时无法使用,我们将在未来提供支持:
28
28
 
29
+ - 微前端(Micro Frontend)
29
30
  - Storybook 调试
30
- - 客户端渲染(CSR)使用 [useLoader](/guides/basic-features/data-fetch.html)
31
+ - 同时使用服务端渲染(SSR)和约定式路由的场景
32
+ - 同时使用静态站点生成(SSG)和约定式路由的场景
31
33
 
32
34
  :::
33
35
 
@@ -86,7 +86,7 @@ export default defineConfig({
86
86
 
87
87
  ### 在自控式路由中使用
88
88
 
89
- **自控式路由**是通过组件代码定义路由,需要应用运行起来才能获取准确的路由信息。因此,无法开箱即用的使用 SSG 功能。此时需要用户提前告知 Modern.js 框架,哪些路由需要开启 SSG 功能。
89
+ **自控式路由**是通过组件代码自定义路由,需要应用运行起来才能获取准确的路由信息。因此,无法开箱即用的使用 SSG 功能。此时需要用户提前告知 Modern.js 框架,哪些路由需要开启 SSG 功能。
90
90
 
91
91
  例如有以下代码,包含多条路由,设置 `output.ssg` 为 `true` 时,默认只会渲染入口路由即 `/`:
92
92
 
@@ -4,7 +4,7 @@ sidebar_position: 10
4
4
 
5
5
  # 测试
6
6
 
7
- Modern.js 默认集成了 [Jest](https://jestjs.io/) 的测试能力。
7
+ Modern.js 默认继承了 [Jest](https://jestjs.io/) 的测试能力。
8
8
 
9
9
  我们首先需要执行 `pnpm run new` 启用「单元测试 / 集成测试」功能:
10
10
 
@@ -488,9 +488,8 @@ export default () => {
488
488
 
489
489
  :::note
490
490
  Modern.js 默认对约定式路由做了一系列资源加载及渲染上的优化,并且提供了开箱即用的 SSR 能力,而这些能力,在使用自控路由时,都需要开发者自行封装,推荐开发者使用约定式路由。
491
- :::
492
491
 
493
- 使用自控式路由时,如果开发者关闭了 [`runtime.router`](/configure/app/runtime/router) 配置,并直接使用 `react-router-dom`,那还需要根据 React Router 文档自行包裹 `Provider`。
492
+ :::
494
493
 
495
494
  ## 其他路由方案
496
495
 
@@ -514,5 +513,19 @@ export default defineConfig({
514
513
  });
515
514
  ```
516
515
 
516
+ ### 常见问题
517
+
518
+ 1. 产物中的代码是 es2015+ 的,期望产物中是 es5 的代码
519
+
520
+ react-router^6 的目前默认产物是 es2020 的,如果需要产物中是 es5 的代码,可以配置 `source.include`,让 react-router 相关包经过 bundler 编译 :
521
+
522
+ ```
523
+ source: {
524
+ source: {
525
+ include: [/@remix-run\/router/, /react-router-dom/, /react-router/],
526
+ }
527
+ }
528
+ ```
529
+
517
530
 
518
531
 
@@ -98,55 +98,36 @@ Modern.js 会将与 package.json 文件中 `name` 字段同名的入口作为主
98
98
 
99
99
  #### 约定式路由
100
100
 
101
- 如果入口中存在 `routes/` 目录,Modern.js 会在启动时扫描 `routes/` 下的文件,基于文件约定,自动生成客户端路由(react-router)。例如:
101
+ 如果入口中存在 `routes/` 目录,Modern.js 会在启动时扫描 `routes/` 下的文件,基于文件约定,自动生成客户端路由(react-router)。
102
102
 
103
- ```bash
104
- .
105
- ├── src
106
- │ └── routes
107
- │ ├── layout.tsx
108
- │ └── page.tsx
109
- ```
110
-
111
- 上述目录中,`layout.tsx` 中导出的组件会作为最外层的组件,`page.tsx` 中导出的组件会作为 `/` 路由的组件。
112
-
113
- 详细内容可以参考[路由](/guides/basic-features/routes#约定式路由)。
103
+ 详细内容可以参考[路由](/guides/basic-features/routes)。
114
104
 
115
- #### 自控式路由
105
+ #### 自定义路由
116
106
 
117
- 如果入口中存在 `App.[jt]sx?` 文件,开发者可以在这个文件中通过代码的方式,设置客户端路由,或者不设置客户端路由。
107
+ 如果入口中存在 `App.[jt]sx?` 文件,开发者可以在这个文件中自由的设置客户端路由,或者不设置客户端路由。
118
108
 
119
- ```tsx
120
- import { BrowserRouter, Route, Routes } from '@modern-js/runtime/router';
121
-
122
- export default () => {
123
- return (
124
- <BrowserRouter>
125
- <Routes>
126
- <Route index element={<div>index</div>} />
127
- <Route path="about" element={<div>about</div>} />
128
- </Routes>
129
- </BrowserRouter>
130
- );
131
- };
132
- ```
109
+ 详细内容可以参考[路由](/guides/basic-features/routes)。
133
110
 
134
- 详细内容可以参考[路由](/guides/basic-features/routes#自控式路由)。
111
+ #### 自定义 App
135
112
 
136
- #### 自定义 Bootstrap
137
-
138
- 如果入口中存在 `index.[jt]sx` 文件,并且当文件默认导出函数时,Modern.js 会将默认的 bootstrap 函数作为入参传入,并用导出的函数替代默认的 bootstrap,这样开发者可以自定义将组件挂载到 DOM 节点上,或在挂载前添加自定义行为。例如:
113
+ 如果入口中存在 `index.[jt]sx` 文件,并且当文件默认导出函数时,Modern.js 还是会根据 runtime 的设置情况生成 createApp 包裹后的代码。在渲染过程中,将 createApp 包裹后的组件作为参数传递给 index 文件导出的函数,这样开发者可以自定义将组件挂载到 DOM 节点上,或在挂载前添加自定义行为。例如:
139
114
 
140
115
  ```tsx
141
- export default (App: React.ComponentType, bootstrap: () => void) => {
116
+ import ReactDOM from 'react-dom/client';
117
+ import { bootstrap } from '@modern-js/runtime';
118
+
119
+ export default (App: React.ComponentType) => {
142
120
  // do something before bootstrap...
143
- initSomething().then(() => {
144
- bootstrap();
145
- })
121
+ bootstrap(App, 'root', undefined, ReactDOM);
146
122
  };
147
123
  ```
148
124
 
149
- 此时,Modern.js 生成的文件内容如下:
125
+ :::warning
126
+ 由于 bootstrap 函数需要兼容 React17 和 React18 的用法,调用 bootstrap 函数时需要手动传入 ReactDOM 参数。
127
+
128
+ :::
129
+
130
+ Modern.js 生成的文件内容如下:
150
131
 
151
132
  ```js
152
133
  import React from 'react';
@@ -159,14 +140,13 @@ const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
159
140
  const MOUNT_ID = 'root';
160
141
 
161
142
  let AppWrapper = null;
162
- let root = null;
163
143
 
164
144
  function render() {
165
145
  AppWrapper = createApp({
166
146
  // runtime 的插件参数...
167
147
  })(App);
168
148
  if (IS_BROWSER) {
169
- customBootstrap(AppWrapper, () => bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM));
149
+ customBootstrap(AppWrapper);
170
150
  }
171
151
  return AppWrapper;
172
152
  }
@@ -190,9 +170,9 @@ import App from './App';
190
170
  ReactDOM.render(<App />, document.getElementById('root'));
191
171
  ```
192
172
 
193
- Modern.js **不推荐**新项目使用这种方式,这种方式丧失了框架的一些能力,如 **`modern.config.js` 文件中的 `runtime` 配置将不会再生效**。但是在项目从其他框架迁移到 Modern.js,例如 CRA,或是自己手动搭建的 webpack 时,这种方式会非常有用。
173
+ Modern.js **不推荐**使用这种方式,这种方式丧失了框架的一些能力,如 **`modern.config.js` 文件中的 `runtime` 配置将不会再生效**。但是在项目从其他框架迁移到 Modern.js,例如 CRA,或是自己手动搭建的 webpack 时,这种方式会非常有用。
194
174
 
195
- ## 使用配置指定入口
175
+ ## 自定义入口
196
176
 
197
177
  大部分存量项目并不是按照 Modern.js 的目录结构来搭建的。如果要改成 Modern.js 约定的目录结构,会存在一定的迁移成本。
198
178
 
@@ -611,7 +611,7 @@ export default (): CliPlugin => ({
611
611
 
612
612
  这样就为 HTML 模版中新增了一个 Script 标签。
613
613
 
614
- {/* ## Server
614
+ <!-- ## Server
615
615
 
616
616
  :::note
617
617
  目前 Server 插件还未完全开放,API 不保证稳定,使用需谨慎。
@@ -692,7 +692,7 @@ export default (): ServerPlugin => ({
692
692
  };
693
693
  },
694
694
  });
695
- ```*/}
695
+ ``` -->
696
696
 
697
697
  ## Runtime
698
698
 
@@ -764,7 +764,7 @@ export default (): Plugin => ({
764
764
  });
765
765
  ```
766
766
 
767
- {/* ### `provide`
767
+ <!-- ### `provide`
768
768
 
769
769
  - 功能:修改需要渲染的 Element
770
770
  - 执行阶段:渲染(SSR/CSR)
@@ -836,4 +836,4 @@ export default (): Plugin => ({
836
836
  };
837
837
  },
838
838
  });
839
- ```*/}
839
+ ``` -->
@@ -34,7 +34,7 @@ schema 如果为选择类型,该字段用于定义选项内容。
34
34
 
35
35
  - label: 展示名称。
36
36
 
37
- ### x-validator
37
+ ### x-validate
38
38
 
39
39
  schema 的验证规则。这里支持 Formily 的校验方式,具体可参考 [Formily 表单校验](https://formilyjs.org/zh-CN/guide/advanced/validate)。
40
40
 
package/package.json CHANGED
@@ -15,13 +15,13 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "0.0.0-next-1683619026219",
18
+ "version": "0.0.0-next-1683620196025",
19
19
  "publishConfig": {
20
20
  "registry": "https://registry.npmjs.org/",
21
21
  "access": "public"
22
22
  },
23
23
  "peerDependencies": {
24
- "@modern-js/builder-doc": "0.0.0-next-1683619026219"
24
+ "@modern-js/builder-doc": "0.0.0-next-1683620196025"
25
25
  },
26
26
  "devDependencies": {
27
27
  "classnames": "^2",
@@ -33,9 +33,9 @@
33
33
  "fs-extra": "^10",
34
34
  "@types/node": "^16",
35
35
  "@types/fs-extra": "^9",
36
- "@modern-js/builder-doc": "0.0.0-next-1683619026219",
37
- "@modern-js/doc-tools": "0.0.0-next-1683619026219",
38
- "@modern-js/doc-plugin-auto-sidebar": "0.0.0-next-1683619026219"
36
+ "@modern-js/builder-doc": "0.0.0-next-1683620196025",
37
+ "@modern-js/doc-plugin-auto-sidebar": "0.0.0-next-1683620196025",
38
+ "@modern-js/doc-tools": "0.0.0-next-1683620196025"
39
39
  },
40
40
  "scripts": {
41
41
  "dev": "modern dev",