@modern-js/main-doc 0.0.0-next-20221203140534 → 0.0.0-next-20221205074243

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 (67) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/new.md +0 -2
  3. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/bootstrap.md +17 -3
  4. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/builder.md +46 -0
  5. package/en/docusaurus-plugin-content-docs/current.json +18 -18
  6. package/package.json +3 -3
  7. package/zh/apis/app/commands/new.md +0 -2
  8. package/zh/apis/app/runtime/app/_category_.json +1 -1
  9. package/zh/apis/app/runtime/bff/_category_.json +1 -1
  10. package/zh/apis/app/runtime/core/_category_.json +1 -1
  11. package/zh/apis/app/runtime/core/bootstrap.md +17 -3
  12. package/zh/apis/app/runtime/model/_category_.json +1 -1
  13. package/zh/apis/app/runtime/router/_category_.json +1 -1
  14. package/zh/apis/app/runtime/ssr/_category_.json +1 -1
  15. package/zh/apis/app/runtime/testing/_category_.json +1 -1
  16. package/zh/apis/app/runtime/utility/_category_.json +1 -1
  17. package/zh/apis/app/runtime/web-server/_category_.json +1 -1
  18. package/zh/configure/app/output/ssg.md +118 -114
  19. package/zh/configure/app/server/ssr.md +0 -2
  20. package/zh/guides/advanced-features/custom-app.md +8 -2
  21. package/zh/guides/advanced-features/ssg.md +74 -63
  22. package/zh/guides/advanced-features/ssr.md +76 -11
  23. package/zh/guides/basic-features/builder.md +46 -0
  24. package/zh/guides/basic-features/css/_category_.json +1 -1
  25. package/zh/guides/basic-features/css/less-sass.md +1 -14
  26. package/zh/guides/basic-features/data-fetch.md +1 -1
  27. package/zh/guides/basic-features/routes.md +32 -35
  28. package/zh/guides/concept/entries.md +4 -4
  29. package/zh/tutorials/first-app/c01-getting-started/1.2-minimal-mwa.md +2 -2
  30. package/zh/tutorials/first-app/c01-getting-started/1.4-enable-ssr.md +5 -2
  31. package/zh/tutorials/first-app/c02-generator-and-studio/2.2-boilerplates.md +4 -6
  32. package/zh/tutorials/first-app/c02-generator-and-studio/2.3-configuration.md +2 -4
  33. package/zh/tutorials/first-app/c03-ide/3.1-setting-up.md +1 -1
  34. package/zh/tutorials/first-app/c03-ide/3.2-hints-in-ide.md +44 -50
  35. package/zh/tutorials/first-app/c03-ide/3.3-autofix-in-ide.md +1 -1
  36. package/zh/tutorials/first-app/c03-ide/3.4-autofix-in-cli.md +4 -4
  37. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.1-use-es6-plus.md +8 -21
  38. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.2-use-typescript.md +37 -13
  39. package/zh/tutorials/first-app/c05-component/5.1-use-ui-library.md +3 -13
  40. package/zh/tutorials/first-app/c05-component/5.2-use-standalone-component.md +1 -21
  41. package/zh/tutorials/first-app/c06-css-and-component/6.1-css-in-js.md +9 -9
  42. package/zh/tutorials/first-app/c06-css-and-component/6.2-utility-class.md +9 -14
  43. package/zh/tutorials/first-app/c06-css-and-component/6.3-postcss.md +7 -7
  44. package/zh/tutorials/first-app/c06-css-and-component/6.4-design-system.md +1 -1
  45. package/zh/tutorials/first-app/c06-css-and-component/6.5-storybook.md +2 -2
  46. package/zh/tutorials/first-app/c06-css-and-component/6.6-testing.md +8 -17
  47. package/zh/tutorials/first-app/c07-app-entry/7.1-intro.md +23 -18
  48. package/zh/tutorials/first-app/c07-app-entry/7.2-add-entry-in-cli.md +30 -30
  49. package/zh/tutorials/first-app/c07-app-entry/7.3-manage-entries-by-hand.md +4 -9
  50. package/zh/tutorials/first-app/c08-client-side-routing/8.1-code-based-routing.md +66 -63
  51. package/zh/tutorials/first-app/c09-bff/9.2-enable-bff.md +35 -33
  52. package/zh/tutorials/first-app/c09-bff/9.3-fetch-bff.md +28 -102
  53. package/zh/tutorials/first-app/c10-model/10.1-application-architecture.md +4 -6
  54. package/zh/tutorials/first-app/c10-model/10.2-add-model.md +3 -3
  55. package/zh/tutorials/first-app/c10-model/10.3-use-model.md +21 -20
  56. package/zh/tutorials/first-app/c10-model/10.4-testing.md +2 -2
  57. package/zh/tutorials/first-app/c11-container/11.1-use-model-with-app-state.md +34 -68
  58. package/zh/tutorials/first-app/c11-container/11.2-add-container.md +40 -37
  59. package/zh/tutorials/first-app/c11-container/11.3-use-loader.md +6 -4
  60. package/zh/tutorials/first-app/c11-container/11.4-testing.md +2 -2
  61. package/zh/tutorials/foundations/introduction.md +1 -1
  62. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/default-alias.md +0 -25
  63. package/zh/apis/app/runtime/default-alias.md +0 -23
  64. package/zh/guides/basic-features/image.md +0 -43
  65. package/zh/guides/topic-detail/compile-speed.md +0 -182
  66. package/zh/guides/troubleshooting/compile.md +0 -379
  67. package/zh/tutorials/first-app/c08-client-side-routing/8.2-file-based-routing.md +0 -310
@@ -15,7 +15,10 @@ import TabItem from '@theme/TabItem';
15
15
  <TabItem value="macOS" label="macOS" default>
16
16
 
17
17
  ```bash
18
- mv src/App.jsx src/App.tsx
18
+ mv src/routes/layout.jsx src/routes/layout.tsx
19
+ mv src/routes/page.jsx src/routes/page.tsx
20
+ mv modern.config.js modern.config.ts
21
+ touch src/modern-app-env.d.ts
19
22
 
20
23
  pnpm add typescript @types/react @types/react-dom @types/node -D
21
24
 
@@ -26,7 +29,10 @@ touch tsconfig.json
26
29
  <TabItem value="Windows" label="Windows">
27
30
 
28
31
  ```bash
29
- mv src/App.jsx src/App.tsx
32
+ mv src/routes/layout.jsx src/routes/layout.tsx
33
+ mv src/routes/page.jsx src/routes/page.tsx
34
+ mv modern.config.js modern.config.ts
35
+ ni src/modern-app-env.d.ts
30
36
 
31
37
  pnpm add typescript @types/react @types/react-dom @types/node -D
32
38
 
@@ -57,28 +63,46 @@ ni tsconfig.json
57
63
  }
58
64
  ```
59
65
 
60
- 打开 `src/App.tsx`,把代码改成以下内容:
66
+ `modern.config.ts` 内容修改如下:
61
67
 
62
68
  ```ts
63
- import React from 'react';
69
+ import { defineConfig } from '@modern-js/app-tools';
64
70
 
71
+ export default defineConfig({
72
+ runtime: {
73
+ router: true,
74
+ state: true,
75
+ },
76
+ });
77
+ ```
78
+
79
+ `modern-app-env.d.ts` 内容如下
80
+
81
+ ```ts
82
+ /// <reference types='@modern-js/app-tools/types' />
83
+ ```
84
+
85
+ 打开 `src/routes/page.tsx`,把代码改成以下内容:
86
+
87
+ ```ts
65
88
  const getAvatar = (users: Array<{ name: string; email: string }>) =>
66
89
  users.map(user => ({
67
90
  ...user,
68
91
  avatar: `https://avatars.dicebear.com/v2/identicon/${user.name}.svg`,
69
92
  }));
70
93
 
71
- const mockData = getAvatar([
72
- { name: 'Thomas', email: 'w.kccip@bllmfbgv.dm' },
73
- { name: 'Chow', email: 'f.lfqljnlk@ywoefljhc.af' },
74
- { name: 'Bradley', email: 'd.wfovsqyo@gpkcjwjgb.fr' },
75
- { name: 'Davis', email: '"t.kqkoj@utlkwnpwk.nu' },
76
- ]);
94
+ const getMockData = () =>
95
+ getAvatar([
96
+ { name: 'Thomas', email: 'w.kccip@bllmfbgv.dm' },
97
+ { name: 'Chow', email: 'f.lfqljnlk@ywoefljhc.af' },
98
+ { name: 'Bradley', email: 'd.wfovsqyo@gpkcjwjgb.fr' },
99
+ { name: 'Davis', email: '"t.kqkoj@utlkwnpwk.nu' },
100
+ ]);
77
101
 
78
- function App() {
102
+ function Index() {
79
103
  return (
80
104
  <ul>
81
- {mockData.map(({ name, avatar, email }) => (
105
+ {getMockData().map(({ name, avatar, email }) => (
82
106
  <li key={name}>
83
107
  <img src={avatar} width={60} height={60} /> ---
84
108
  <span>{name}</span> ---
@@ -89,7 +113,7 @@ function App() {
89
113
  );
90
114
  }
91
115
 
92
- export default App;
116
+ export default Index;
93
117
  ```
94
118
 
95
119
  可以看到,跟 ES6+ 的代码相比有以下不同:
@@ -14,26 +14,16 @@ title: 使用主流组件库
14
14
  pnpm add antd
15
15
  ```
16
16
 
17
- 之前章节介绍过,Modern.js 支持在项目创建后继续为项目增加功能,我们执行 `pnpm run new`,进行如下选择,开启 Less 支持。
18
-
19
- ```bash
20
- # 启用可选功能
21
- 启用 Tailwind CSS 支持
22
- ❯ 启用 Less 支持
23
- 启用 Sass 支持
24
- ...
25
- ```
26
-
27
- 修改 `src/App.tsx`,在顶部导入组件:
17
+ 修改 `src/routes/page.tsx`,在顶部导入组件:
28
18
 
29
19
  ```js
30
20
  import { List } from 'antd';
31
21
  ```
32
22
 
33
- 修改 App 组件的实现:
23
+ 修改 Index 组件的实现:
34
24
 
35
25
  ```ts
36
- function App() {
26
+ function Index() {
37
27
  return (
38
28
  <div>
39
29
  <List
@@ -12,7 +12,7 @@ title: 使用独立开源组件
12
12
  pnpm add react-ladda ladda
13
13
  ```
14
14
 
15
- 在 `src/App.tsx` 里导入组件,同时手动导入需要的 CSS:
15
+ 在 `src/routes/page.tsx` 里导入组件,同时手动导入需要的 CSS:
16
16
 
17
17
  ```ts
18
18
  import LaddaButton, { S, SLIDE_UP } from 'react-ladda';
@@ -46,26 +46,6 @@ import 'ladda/dist/ladda.min.css';
46
46
 
47
47
  `react-ladda` 组件库没有提供 types 文件,我们添加一个 `.d.ts` 文件:
48
48
 
49
- import Tabs from '@theme/Tabs';
50
- import TabItem from '@theme/TabItem';
51
-
52
- <Tabs>
53
- <TabItem value="macOS" label="macOS" default>
54
-
55
- ```bash
56
- touch src/modern-app-env.d.ts
57
- ```
58
-
59
- </TabItem>
60
- <TabItem value="Windows" label="Windows">
61
-
62
- ```bash
63
- ni src/modern-app-env.d.ts
64
- ```
65
-
66
- </TabItem>
67
- </Tabs>
68
-
69
49
  在 `modern-app-env.d.ts` 中添加模块定义:
70
50
 
71
51
  ```ts
@@ -21,7 +21,7 @@ Modern.js 开箱即用的支持 CSS Modules,但我们更推荐优先采用 CSS
21
21
 
22
22
  Modern.js 同样开箱即用的支持 styled-components,既不需要安装依赖,也不需要做任何配置。
23
23
 
24
- 在 `src/App.tsx` 里修改顶部的代码:
24
+ 在 `src/routes/page.tsx` 里修改顶部的代码:
25
25
 
26
26
  ```js
27
27
  import styled from '@modern-js/runtime/styled';
@@ -63,30 +63,30 @@ import TabItem from '@theme/TabItem';
63
63
  <TabItem value="macOS" label="macOS" default>
64
64
 
65
65
  ```bash
66
- mkdir -p src/components/Avatar
67
- touch src/components/Avatar/index.tsx
66
+ mkdir -p src/routes/components/Avatar
67
+ touch src/routes/components/Avatar/index.tsx
68
68
  ```
69
69
 
70
70
  </TabItem>
71
71
  <TabItem value="Windows" label="Windows">
72
72
 
73
73
  ```powershell
74
- mkdir -p src/components/Avatar
75
- ni src/components/Avatar/index.tsx
74
+ mkdir -p src/routes/components/Avatar
75
+ ni src/routes/components/Avatar/index.tsx
76
76
  ```
77
77
 
78
78
  </TabItem>
79
79
  </Tabs>
80
80
 
81
- 把 `src/App.tsx` 里的 Avatar 实现删掉,改成:
81
+ 把 `src/routes/page.tsx` 里的 Avatar 实现删掉,改成:
82
82
 
83
- ```js
83
+ ```ts
84
84
  import Avatar from './components/Avatar';
85
85
  ```
86
86
 
87
- `src/components/Avatar/index.tsx` 的内容:
87
+ `src/routes/components/Avatar/index.tsx` 的内容:
88
88
 
89
- ```js
89
+ ```ts
90
90
  import styled from '@modern-js/runtime/styled';
91
91
 
92
92
  const Avatar = styled.img`
@@ -21,15 +21,10 @@ Modern.js 集成了主流、轻量、通用的 Utility Class 工具库 [Tailwind
21
21
  ```bash
22
22
  # 启用可选功能
23
23
  ❯ 启用 Tailwind CSS 支持
24
- 启用 Sass 支持
25
24
  ...
26
25
  ```
27
26
 
28
- :::info
29
- 因为我们之前已经开启了 Less 支持,所以再次添加可选功能时,不再有这个选项。
30
- :::
31
-
32
- 在 `src/App.tsx` 顶部引入 Tailwind CSS 的 css 文件,就可以开始快速实现专业的 UI:
27
+ `src/routes/page.tsx` 顶部引入 Tailwind CSS 的 css 文件,就可以开始快速实现专业的 UI:
33
28
 
34
29
  ```js
35
30
  import 'tailwindcss/base.css';
@@ -46,22 +41,22 @@ import TabItem from '@theme/TabItem';
46
41
  <TabItem value="macOS" label="macOS" default>
47
42
 
48
43
  ```bash
49
- mkdir -p src/components/Item
50
- touch src/components/Item/index.tsx
44
+ mkdir -p src/routes/components/Item
45
+ touch src/routes/components/Item/index.tsx
51
46
  ```
52
47
 
53
48
  </TabItem>
54
49
  <TabItem value="Windows" label="Windows">
55
50
 
56
51
  ```powershell
57
- mkdir -p src/components/Item
58
- ni src/components/Item/index.tsx
52
+ mkdir -p src/routes/components/Item
53
+ ni src/routes/components/Item/index.tsx
59
54
  ```
60
55
 
61
56
  </TabItem>
62
57
  </Tabs>
63
58
 
64
- 修改 `src/App.tsx`,把 `List` 的 `render` 实现交给 `Item` 组件:
59
+ 修改 `src/routes/page.tsx`,把 `List` 的 `render` 实现交给 `Item` 组件:
65
60
 
66
61
  ```js
67
62
  import { List } from 'antd';
@@ -83,7 +78,7 @@ const mockData = getAvatar([
83
78
  { name: 'Davis', email: '"t.kqkoj@utlkwnpwk.nu' },
84
79
  ]);
85
80
 
86
- function App() {
81
+ function Index() {
87
82
  return (
88
83
  <div className="container lg mx-auto">
89
84
  <List
@@ -94,12 +89,12 @@ function App() {
94
89
  );
95
90
  }
96
91
 
97
- export default App;
92
+ export default Index;
98
93
  ```
99
94
 
100
95
  在父容器的上使用了 [Utility Class](https://tailwindcss.com/docs/container) ,快速实现了最基本的 [RWD](https://tailwindcss.com/docs/responsive-design)(最大宽度、居中)。
101
96
 
102
- 接下来实现 `src/components/Item/index.tsx`:
97
+ 接下来实现 `src/routes/components/Item/index.tsx`:
103
98
 
104
99
  ```tsx
105
100
  import Avatar from '../Avatar';
@@ -17,28 +17,28 @@ import TabItem from '@theme/TabItem';
17
17
  <TabItem value="macOS" label="macOS" default>
18
18
 
19
19
  ```bash
20
- mkdir -p src/styles
21
- touch src/styles/utils.css
20
+ mkdir -p src/routes/styles
21
+ touch src/routes/styles/utils.css
22
22
  ```
23
23
 
24
24
  </TabItem>
25
25
  <TabItem value="Windows" label="Windows">
26
26
 
27
27
  ```powershell
28
- mkdir -p src/styles
29
- ni src/styles/utils.css
28
+ mkdir -p src/routes/styles
29
+ ni src/routes/styles/utils.css
30
30
  ```
31
31
 
32
32
  </TabItem>
33
33
  </Tabs>
34
34
 
35
- 在 `src/App.tsx` 里导入 `utils.css`:
35
+ 在 `src/routes/page.tsx` 里导入 `utils.css`:
36
36
 
37
37
  ```js
38
38
  import './styles/utils.css';
39
39
  ```
40
40
 
41
- 在 `src/styles/utils.css` 里实现一个叫作 `custom-text-gray` 的 Utility Class。
41
+ 在 `src/routes/styles/utils.css` 里实现一个叫作 `custom-text-gray` 的 Utility Class。
42
42
 
43
43
  ```css
44
44
  :root {
@@ -54,7 +54,7 @@ import './styles/utils.css';
54
54
  Modern.js 集成了 [PostCSS](/docs/guides/basic-features/css/postcss),支持现代 CSS 语法特性,比如 [custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/--*)。
55
55
  :::
56
56
 
57
- 在 `src/components/Item/index.tsx` 里使用,把:
57
+ 在 `src/routes/components/Item/index.tsx` 里使用,把:
58
58
 
59
59
  ```js
60
60
  <div className="ml-4 flex-1 flex justify-between">
@@ -61,7 +61,7 @@ export default defineConfig({
61
61
  });
62
62
  ```
63
63
 
64
- 修改 `src/Item/index.tsx` 的 button 组件代码
64
+ 修改 `src/routes/components/Item/index.tsx` 的 button 组件代码
65
65
 
66
66
  ```js
67
67
  <button
@@ -32,14 +32,14 @@ import TabItem from '@theme/TabItem';
32
32
  <TabItem value="macOS" label="macOS" default>
33
33
 
34
34
  ```bash
35
- touch src/components/Avatar/index.stories.tsx
35
+ touch src/routes/components/Avatar/index.stories.tsx
36
36
  ```
37
37
 
38
38
  </TabItem>
39
39
  <TabItem value="Windows" label="Windows">
40
40
 
41
41
  ```powershell
42
- ni src/components/Avatar/index.stories.tsx
42
+ ni src/routes/components/Avatar/index.stories.tsx
43
43
  ```
44
44
 
45
45
  </TabItem>
@@ -20,14 +20,14 @@ import TabItem from '@theme/TabItem';
20
20
  <TabItem value="macOS" label="macOS" default>
21
21
 
22
22
  ```bash
23
- touch src/components/Item/index.test.tsx
23
+ touch src/routes/components/Item/index.test.tsx
24
24
  ```
25
25
 
26
26
  </TabItem>
27
27
  <TabItem value="Windows" label="Windows">
28
28
 
29
29
  ```powershell
30
- ni src/components/Item/index.test.tsx
30
+ ni src/routes/components/Item/index.test.tsx
31
31
  ```
32
32
 
33
33
  </TabItem>
@@ -39,16 +39,16 @@ ni src/components/Item/index.test.tsx
39
39
  <TabItem value="macOS" label="macOS" default>
40
40
 
41
41
  ```bash
42
- mkdir -p src/components/Item/__tests__/
43
- touch src/components/Item/__tests__/index.tsx
42
+ mkdir -p src/routes/components/Item/__tests__/
43
+ touch src/routes/components/Item/__tests__/index.tsx
44
44
  ```
45
45
 
46
46
  </TabItem>
47
47
  <TabItem value="Windows" label="Windows">
48
48
 
49
49
  ```powershell
50
- mkdir -p src/components/Item/__tests__/
51
- ni src/components/Item/__tests__/index.tsx
50
+ mkdir -p src/routes/components/Item/__tests__/
51
+ ni src/routes/components/Item/__tests__/index.tsx
52
52
  ```
53
53
 
54
54
  </TabItem>
@@ -81,12 +81,6 @@ describe('Item', () => {
81
81
  });
82
82
  ```
83
83
 
84
- 在之前章节创建的 `modern-app-env.d.ts` 文件 **顶部**([`///` 语法只在文件顶部生效](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#:~:text=Triple-slash%20directives%20are%20only%20valid%20at%20the%20top%20of%20their%20containing%20file.)) 加上类型定义:
85
-
86
- ```ts
87
- /// <reference types="@modern-js/plugin-testing/type" />
88
- ```
89
-
90
84
  :::info 注
91
85
  更多相关内容可以查看 [Test API](/docs/apis/app/runtime/testing/render)。
92
86
  :::
@@ -96,15 +90,12 @@ describe('Item', () => {
96
90
  ```bash
97
91
  > modern test
98
92
 
99
- PASS src/components/Item/index.test.tsx
100
- Item
101
- ✓ should have contents (27 ms)
93
+ PASS src/routes/components/Item/index.test.tsx
102
94
 
103
95
  Test Suites: 1 passed, 1 total
104
96
  Tests: 1 passed, 1 total
105
97
  Snapshots: 0 total
106
- Time: 1.048 s, estimated 2 s
107
- Ran all test suites.
98
+ Time: 1.708 s
108
99
  ```
109
100
 
110
101
  ---
@@ -8,37 +8,42 @@ title: 入口的用途​​​
8
8
 
9
9
  ```md
10
10
  .
11
- ├── .vscode/
12
- ├── src/
13
- │ ├── components/
14
- │ │ ├── Avatar/
15
- │ │ │ ├── index.stories.tsx
16
- │ │ │ └── index.tsx
17
- │ │ └── Item/
18
- │ │ ├── index.test.tsx
19
- │ │ └── index.tsx
20
- │ ├── styles/
21
- │ │ └── utils.css
22
- │ ├── .eslintrc.json
23
- │ ├── App.css
24
- │ ├── App.tsx
25
- │ └── modern-app-env.d.ts
26
- ├── .editorconfig
11
+ ├── .eslintrc.js
27
12
  ├── .gitignore
13
+ ├── .husky
28
14
  ├── .npmrc
29
15
  ├── .nvmrc
16
+ ├── .prettierrc
17
+ ├── .vscode
30
18
  ├── README.md
19
+ ├── modern.config.ts
31
20
  ├── package.json
32
21
  ├── pnpm-lock.yaml
22
+ ├── src
23
+ │ ├── .eslintrc.js
24
+ │ ├── modern-app-env.d.ts
25
+ │ └── routes
26
+ │ ├── components
27
+ │ │ ├── Avatar
28
+ │ │ │ ├── index.stories.tsx
29
+ │ │ │ └── index.tsx
30
+ │ │ └── Item
31
+ │ │ ├── index.test.tsx
32
+ │ │ └── index.tsx
33
+ │ ├── index.css
34
+ │ ├── layout.tsx
35
+ │ ├── page.tsx
36
+ │ └── styles
37
+ │ └── utils.css
33
38
  └── tsconfig.json
34
39
  ```
35
40
 
36
41
  hello-modern 项目是一个应用工程,`src/` 目录里是应用工程源代码的主要部分,我们称之为【 Universal App 代码(大一统应用代码)】—— 既可以在客户端运行又可以在服务器端运行,有多种运行模式和部署模式,既能实现多页(MPA)也能实现单页(SPA)。
37
42
 
38
- 我们把 `src/App.tsx` 称作【 应用入口(App Entry)】,一个应用工程可以有一到多个应用入口。
43
+ 我们把 `src/routes` 称作【 应用入口(App Entry)】,一个应用工程可以有一到多个应用入口。
39
44
 
40
45
  :::info 注
41
- 应用入口不止 `App.[jt]sx` 一种,之后章节中会再次介绍。
46
+ 应用入口不止 `src/routes` 一种,之后章节中会再次介绍。
42
47
  :::
43
48
 
44
49
  :::info 注
@@ -23,38 +23,46 @@ Modern.js 支持自动创建新入口,前面的章节中提到过,`pnpm run
23
23
 
24
24
  ```md
25
25
  .
26
- ├── .vscode/
27
- ├── src/
28
- │ ├── hello-modern/
29
- │ │ ├── components/
30
- │ │ │ ├── Avatar/
31
- │ │ │ │ ├── index.stories.tsx
32
- │ │ │ │ └── index.tsx
33
- │ │ │ └── Item/
34
- │ │ │ ├── index.test.tsx
35
- │ │ │ └── index.tsx
36
- │ │ ├── styles/
37
- │ │ │ └── utils.css
38
- │ │ ├── App.css
39
- │ │ └── App.tsx
40
- │ ├── landing-page/
41
- │ │ ├── App.css
42
- │ │ └── App.tsx
43
- │ ├── .eslintrc.json
44
- │ └── modern-app-env.d.ts
45
- ├── .editorconfig
26
+ ├── .eslintrc.js
46
27
  ├── .gitignore
28
+ ├── .husky
47
29
  ├── .npmrc
48
30
  ├── .nvmrc
31
+ ├── .prettierrc
32
+ ├── .vscode
49
33
  ├── README.md
34
+ ├── modern.config.ts
50
35
  ├── package.json
51
36
  ├── pnpm-lock.yaml
37
+ ├── src
38
+ │ ├── .eslintrc.js
39
+ │ ├── hello-modern
40
+ │ │ ├── index.test.ts
41
+ │ │ └── routes
42
+ │ │ ├── components
43
+ │ │ │ ├── Avatar
44
+ │ │ │ │ ├── index.stories.tsx
45
+ │ │ │ │ └── index.tsx
46
+ │ │ │ └── Item
47
+ │ │ │ ├── index.test.tsx
48
+ │ │ │ └── index.tsx
49
+ │ │ ├── index.css
50
+ │ │ ├── layout.tsx
51
+ │ │ ├── page.tsx
52
+ │ │ └── styles
53
+ │ │ └── utils.css
54
+ │ ├── landing-page
55
+ │ │ └── routes
56
+ │ │ ├── index.css
57
+ │ │ ├── layout.tsx
58
+ │ │ └── page.tsx
59
+ │ └── modern-app-env.d.ts
52
60
  └── tsconfig.json
53
61
  ```
54
62
 
55
63
  可以看到联系人列表应用的文件,都被自动重构到 `src/hello-modern/` 里。
56
64
 
57
- 同时新建了一个 `src/landing-page/`,里面同样有 `App.tsx`(`pnpm run new` 命令只做了这些事,所以你也可以很容易的手动创建新入口或修改入口)
65
+ 同时新建了一个 `src/landing-page/`,里面同样有 `routes/*`(`pnpm run new` 命令只做了这些事,所以你也可以很容易的手动创建新入口或修改入口)
58
66
 
59
67
  执行 `pnpm run dev`,显示:
60
68
 
@@ -74,15 +82,7 @@ Modern.js 框架的设计原则之一是【[约定优于配置(Convention over
74
82
 
75
83
  其他入口的 URL,是在根路径后追加入口名,比如 `http://localhost:8080/landing-page`。
76
84
 
77
- :::info
78
- `src/` 下如果有 `App.[jt]sx`,就认为这个应用工程是单入口的,`src/` 下的其他文件和目录,都会被视为入口内部的文件。
79
-
80
- `src/` 下如果没有 `App.[jt]sx`,那么 `src/` **下一级**目录里,如果有 `App.[jt]sx`,这个目录就会被视为一个应用入口。
81
-
82
- `App.jsx` 被看作约定中**标识**,也有其他形式的**标识**,之后的章节中会继续介绍。
83
- :::
84
-
85
- 接下来,我们把 `src/hello-modern/App.tsx` 重命名为 `src/contacts/App.tsx`:
85
+ 接下来,我们把 `src/hello-modern/` 重命名为 `src/contacts/`:
86
86
 
87
87
  ```bash
88
88
  mv src/hello-modern src/contacts
@@ -8,9 +8,8 @@ title: 管理应用入口​​​
8
8
 
9
9
  我们可以在 `package.json` 中的 `modernConfig`,或是在符合[业界主流惯例](https://github.com/davidtheclark/cosmiconfig)的 Modern.js 配置文件里,自己写代码来控制项目的配置。
10
10
 
11
- 之前的章节中,我们都是直接修改 `package.json` 中的 `modernConfig` 字段来实现修改配置。
12
11
 
13
- 现在,让我们在项目目录下,新建一个 `modern.config.ts`(若已新建可忽略),并在里面添加内容:
12
+ 现在,让我们在项目目录 `modern.config.ts` 里面添加内容:
14
13
 
15
14
  ```typescript title="modern.config.ts"
16
15
  export default defineConfig({
@@ -29,19 +28,15 @@ export default defineConfig({
29
28
 
30
29
  如果注释掉 `ssrByEntries` 和它的值,landing-page 的 SSR 功能就恢复开启了。
31
30
 
32
- :::info 注
33
- 当相同配置字段出现于两个文件中时, `package.json` 中 `modernConfig` 字段里的配置会优先于 `modern.config.js` 中的配置。
34
- :::
35
-
36
31
  当需要配置包含复杂逻辑的选项时,比如,开发者想在项目中使用 `*.myext` 文件,这是一种非主流的文件类型,Modern.js 没有默认集成对它的支持。
37
32
 
38
- 所以,开发者可以在 `modern.config.js` 里增加对它的支持(通过webpack配置),如下所示:
33
+ 所以,开发者可以在 `modern.config.ts` 里增加对它的支持(通过webpack配置),如下所示:
39
34
 
40
35
  :::info 注
41
36
  更多 webpack 配置相关可以查看 [Webpack 配置文档](/docs/configure/app/tools/webpack)。
42
37
  :::
43
38
 
44
- ```js
39
+ ```ts
45
40
  // 注:以下为伪代码,loader等名字皆为虚构,仅做演示使用
46
41
  export default defineConfig({
47
42
  tools: {
@@ -59,7 +54,7 @@ export default defineConfig({
59
54
 
60
55
  这个需求要修改 webpack 配置,用 Modern.js 配置的`tools.webpack`选项来实现显然是更方便的。
61
56
 
62
- 还有一些时候,需要一些更复杂的逻辑来做设置,比如需要 JS 变量、表达式、导入模块等,这种时候也适合用 `modern.config.js` 来手动配置,比如:
57
+ 还有一些时候,需要一些更复杂的逻辑来做设置,比如需要 JS 变量、表达式、导入模块等,这种时候也适合用 `modern.config.ts` 来手动配置,比如:
63
58
 
64
59
  ```js
65
60
  export default defineConfig({