@modern-js/main-doc 0.0.0-nightly-20230920160608 → 0.0.0-nightly-20230922160540

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.
@@ -6,7 +6,7 @@ $ pnpm run dev
6
6
  > modern dev
7
7
 
8
8
  info Starting dev server...
9
- ready Client compiled in 50ms
9
+ ready Client compiled in 50 ms
10
10
 
11
11
  > Local: http://localhost:8080/
12
12
  > Network: http://192.168.0.1:8080/
@@ -39,8 +39,8 @@ import { defineConfig } from '@modern-js/app-tools';
39
39
  export default defineConfig({
40
40
  source: {
41
41
  entries: {
42
- // Specify a new entry named entry_customize
43
- entry_customize: './src/home/test/index.ts',
42
+ // Specify a new entry named 'my-entry'
43
+ 'my-entry': './src/home/test/index.ts',
44
44
  },
45
45
  disableDefaultEntries: true,
46
46
  },
@@ -90,9 +90,10 @@ import { defineConfig } from '@modern-js/app-tools';
90
90
  export default defineConfig({
91
91
  source: {
92
92
  entries: {
93
- entry_customize: {
93
+ 'my-entry': {
94
94
  // entry file path
95
- entry: './src/home/test/App.tsx',
95
+ entry: './src/my-page/index.tsx',
96
+ disableMount: true,
96
97
  },
97
98
  },
98
99
  // Disable default entry scanning
@@ -111,8 +112,8 @@ If you want to disable the logic of Modern.js automatically generating entry fil
111
112
  export default defineConfig({
112
113
  source: {
113
114
  entries: {
114
- entry_customize: {
115
- entry: './src/home/test/index.tsx',
115
+ 'my-entry': {
116
+ entry: './src/my-page/index.tsx',
116
117
  disableMount: true,
117
118
  },
118
119
  },
@@ -32,7 +32,7 @@ The project initialized by Modern.js is a single entry (SPA) project, with the f
32
32
 
33
33
  In a Modern.js project, you can easily switch from single entry to multiple entries by running `pnpm run new` in the project directory and creating an entry:
34
34
 
35
- ```bash
35
+ ```text
36
36
  ? Please select the operation you want: Create Element
37
37
  ? Please select the type of element to create: New "entry"
38
38
  ? Please fill in the entry name: new-entry
@@ -56,7 +56,7 @@ After running the command, Modern.js will automatically generate a new entry dir
56
56
 
57
57
  The original entry code has been moved to a directory with the same name as the `name` field in `package.json`, and a `new-entry` entry directory has been created.
58
58
 
59
- After running `pnpm run dev`, you can see a new route named `/new-entry` has been added, and the migrated code route has not changed.
59
+ You can run `pnpm run dev` to start the development server. At this point, you will see a new route named `/new-entry` added, and the existing page routes remain unchanged.
60
60
 
61
61
  :::tip
62
62
  Modern.js will use the entry with the same name as the `name` field in `package.json` as the main entry. The route of the main entry is `/`, and the route of other entries is `/{entryName}`.
@@ -76,7 +76,9 @@ import EntryMode from '@site-docs-en/components/entry-mode.mdx';
76
76
  By default, Modern.js scans the files under `src/` before starting the project, identifies the entry, and generates the corresponding server-side route.
77
77
 
78
78
  :::tip
79
- You can modify the directory for entry identification by using the [source.entriesDir](/configure/app/source/entries-dir) config.
79
+
80
+ - You can custom the recognition directory for page entries by using [source.entriesDir](/configure/app/source/entries-dir).
81
+ - If you need to customize the entry points, please refer to [Custom Entries](#custom-entries).
80
82
 
81
83
  :::
82
84
 
@@ -98,7 +100,7 @@ When the project is not a single entry application, Modern.js will further look
98
100
 
99
101
  ### Framework Mode Entry
100
102
 
101
- Framework mode refers to the need to use Modern.js framework capabilities, such as Router, SSR, integrated calls, etc. Under this type of entry convention, the entry defined by the developer is not a real webpack compilation entry. Modern.js will generate a wrapped entry during startup, and you can find the real entry in `node_modules/.modern/{entryName}/index.js`.
103
+ The framework mode refers to the need to use the framework capabilities of Modern.js, such as nested routing, SSR, and integrated BFF, etc. Under this kind of entry convention, the entry defined by the developer is not the actual compilation entry. When Modern.js is launched, it generates a wrapped entry, and the real entry can be found at `node_modules/.modern/[entryName]/index.js`.
102
104
 
103
105
  #### Conventional Routing
104
106
 
@@ -146,7 +148,7 @@ export default (App: React.ComponentType, bootstrap: () => void) => {
146
148
  // do something before bootstrap...
147
149
  initSomething().then(() => {
148
150
  bootstrap();
149
- })
151
+ });
150
152
  };
151
153
  ```
152
154
 
@@ -181,9 +183,11 @@ export default AppWrapper;
181
183
 
182
184
  ### Build Mode Entry
183
185
 
184
- Build mode refers to not using any Modern.js runtime capabilities and completely defining the project's webpack entry by the developer.
186
+ Build mode refers to the mode where the entry point of the page is not automatically generated by Modern.js, but is fully defined by the developers themselves.
187
+
188
+ When there is an `index.[jt]sx` file in the entry directory and it is not exported as a function using `export default`, this type of file will be recognized as the entry module for webpack or Rspack.
185
189
 
186
- If there is an `index.[jt]sx` file in the entry and it does not export a default function, then this file is the real webpack entry file. Similar to [Create React App](https://github.com/facebook/create-react-app), you need to mount the component to the DOM node by yourself, add hot update code, etc. For example:
190
+ In this case, Modern.js will not generate the entry code automatically. Therefore, you need to manually mount the component to the DOM node, for example:
187
191
 
188
192
  ```js title=src/index.jsx
189
193
  import React from 'react';
@@ -193,42 +197,39 @@ import App from './App';
193
197
  ReactDOM.render(<App />, document.getElementById('root'));
194
198
  ```
195
199
 
196
- Modern.js **does not recommend** using this method for new projects, as it loses some of the framework's capabilities, such as the `runtime` configuration in the `modern.config.js` file will no longer take effect. However, this method can be very useful when migrating projects from other frameworks to Modern.js, such as CRA, or manually building webpack.
200
+ This approach is equivalent to enabling the [source.entries.disableMount](/configure/app/source/entries) option in Modern.js. When you use this approach, **you will not be able to use the runtime capabilities of the Modern.js framework**, such as the `runtime` configuration in the modern.config.js file will no longer take effect.
197
201
 
198
- ## Specifying Entry Using Configuration
202
+ ## Custom Entries
199
203
 
200
- Most existing projects are not built according to the directory structure of Modern.js. If you want to change to the directory structure of Modern.js, there will be certain migration costs.
204
+ In some cases, you may need to customize the entry configuration instead of using the entry conventions provided by Modern.js.
201
205
 
202
- In this case, in addition to using file conventions to generate entries, you can manually configure the entry in `modern.config.[jt]s`.
206
+ For example, if you want to migrate a non-Modern.js project to Modern.js and it is not structured according to Modern.js directory structure, there might be some migration costs involved in changing it to the conventional structure. In such cases, you can custom the entries.
203
207
 
204
- ```ts title="modern.config.ts"
205
- export default defineConfig({
206
- source: {
207
- entries: {
208
- // Specify a new entry named entry_customize
209
- entry_customize: './src/home/test/index.ts',
210
- },
211
- // Disable default ingress scanning
212
- disableDefaultEntries: true,
213
- },
214
- });
215
- ```
208
+ Modern.js provides the following configuration options that you can set in [modern.config.ts](/configure/app/usage):
216
209
 
217
- ### Disable Default Entry Scanning
210
+ - [source.entries](/configure/app/source/entries): Used to set custom entry objects.
211
+ - [source.disableDefaultEntries](/configure/app/source/disable-default-entries): Used to disable Modern.js's default entry scanning behavior. When you use custom entries, parts of your project structure might coincidentally match the Modern.js conventional directory structure, but you may not want Modern.js to generate entry configurations for them. Enabling this option can help avoid this issue.
218
212
 
219
- When using custom entries, part of the project structure may coincidentally hit the directory conventions of Modern.js, but in fact, this part of the directory is not the real entry.
213
+ ### Example
220
214
 
221
- Modern.js provides the `disableDefaultEntries` configuration to disable the default entry scanning rules. When you need to customize the entry, you generally need to use `disableDefaultEntries` in combination with `entries`. This way, some existing projects can be quickly migrated without modifying the directory structure.
215
+ Here is an example of a custom entry point. You can also refer to the documentation of the corresponding configuration options for more usage.
222
216
 
223
217
  ```ts title="modern.config.ts"
224
218
  export default defineConfig({
225
219
  source: {
220
+ entries: {
221
+ // Specify an entry named 'my-entry'
222
+ 'my-entry': {
223
+ // Path to the entry module
224
+ entry: './src/my-page/index.tsx',
225
+ // Disable automatic generation of entry code by Modern.js
226
+ disableMount: true,
227
+ },
228
+ },
229
+ // Disable entry scanning behavior
226
230
  disableDefaultEntries: true,
227
231
  },
228
232
  });
229
233
  ```
230
234
 
231
- :::tip
232
- For detailed usage, please refer to [source.entries](/configure/app/source/entries) and [source.disableDefaultEntries](/configure/app/source/disable-default-entries).
233
-
234
- :::
235
+ Note that when you enable `disableMount`, **you won't be able to use the runtime capabilities of the Modern.js framework**, such as the `runtime` configuration in the modern.config.ts file.
@@ -92,7 +92,7 @@ $ pnpm run build
92
92
  > modern build
93
93
 
94
94
  info Staring production build...
95
- ready Client compiled in 50ms
95
+ ready Client compiled in 50 ms
96
96
  info Production file sizes:
97
97
 
98
98
  File Size Gzipped
@@ -6,7 +6,7 @@ $ pnpm run dev
6
6
  > modern dev
7
7
 
8
8
  info Starting dev server...
9
- ready Client compiled in 50ms
9
+ ready Client compiled in 50 ms
10
10
 
11
11
  > Local: http://localhost:8080/
12
12
  > Network: http://192.168.0.1:8080/
@@ -39,8 +39,8 @@ import { defineConfig } from '@modern-js/app-tools';
39
39
  export default defineConfig({
40
40
  source: {
41
41
  entries: {
42
- // 指定一个名称为 entry_customize 的新入口
43
- entry_customize: './src/home/test/index.ts',
42
+ // 指定一个名称为 'my-entry' 的新入口
43
+ 'my-entry': './src/home/test/index.ts',
44
44
  },
45
45
  // 禁用默认入口扫描
46
46
  disableDefaultEntries: true,
@@ -92,9 +92,10 @@ import { defineConfig } from '@modern-js/app-tools';
92
92
  export default defineConfig({
93
93
  source: {
94
94
  entries: {
95
- entry_customize: {
95
+ 'my-entry': {
96
96
  // 入口文件路径
97
- entry: './src/home/test/index.tsx',
97
+ entry: './src/my-page/index.tsx',
98
+ disableMount: true,
98
99
  },
99
100
  },
100
101
  // 禁用默认入口扫描
@@ -113,8 +114,8 @@ export default defineConfig({
113
114
  export default defineConfig({
114
115
  source: {
115
116
  entries: {
116
- entry_customize: {
117
- entry: './src/home/test/index.tsx',
117
+ 'my-entry': {
118
+ entry: './src/my-page/index.tsx',
118
119
  disableMount: true,
119
120
  },
120
121
  },
@@ -6,9 +6,9 @@ sidebar_position: 1
6
6
 
7
7
  通过本章节,你可以了解到 Modern.js 中的入口约定,以及如何自定义入口。
8
8
 
9
- ## 什么是入口(Entry)
9
+ ## 什么是入口
10
10
 
11
- **入口指的是一个页面的起始模块。**
11
+ **入口(Entry)指的是一个页面的起始模块。**
12
12
 
13
13
  在 Modern.js 项目中,每一个入口对应一个独立的页面,也对应一条服务端路由。默认情况下,Modern.js 会基于目录约定来自动确定页面的入口,同时也支持通过配置项来自定义入口。
14
14
 
@@ -56,7 +56,7 @@ Modern.js 初始化的项目是单入口的(SPA),项目结构如下:
56
56
 
57
57
  原本的入口代码被移动到了和 `package.json` 中 `name` 同名的目录下,并创建了 `new-entry` 入口目录。
58
58
 
59
- 执行 `pnpm run dev` 后,可以看到新增了一条名为 `/new-entry` 的路由,并且被迁移的代码路由并未发生变化。
59
+ 你可以执行 `pnpm run dev` 启动开发服务,此时可以看到新增了一条名为 `/new-entry` 的路由,并且原有页面的路由并未发生变化。
60
60
 
61
61
  :::tip
62
62
  Modern.js 会将与 `package.json` 文件中 `name` 字段同名的入口作为主入口,主入口的路由为 `/`,其他入口的路由为 `/{entryName}`。
@@ -76,7 +76,8 @@ import EntryMode from '@site-docs/components/entry-mode.mdx';
76
76
  默认情况下,Modern.js 启动项目前会对 `src/` 下的文件进行扫描,识别入口,并生成对应的服务端路由。
77
77
 
78
78
  :::tip
79
- 可以通过 [source.entriesDir](/configure/app/source/entries-dir) 修改页面的入口识别目录。
79
+ - 你可以通过 [source.entriesDir](/configure/app/source/entries-dir) 修改页面入口的识别目录。
80
+ - 如果你需要自定义入口,请参考 [自定义入口](#自定义入口)。
80
81
 
81
82
  :::
82
83
 
@@ -98,7 +99,7 @@ import EntryMode from '@site-docs/components/entry-mode.mdx';
98
99
 
99
100
  ### 框架模式入口
100
101
 
101
- 框架模式指需要使用 Modern.js 框架能力,例如 Router、SSR、一体化调用等。这类入口约定下,开发者定义的入口并不是真正的 webpack 编译入口。Modern.js 在启动时会生成一个封装过的入口,可以在 `node_modules/.modern/{entryName}/index.js` 找到真正的入口。
102
+ 框架模式指的是需要使用 Modern.js 的框架能力,例如嵌套路由、SSR、一体化调用等。这类入口约定下,开发者定义的入口并不是真正的编译入口。Modern.js 在启动时会生成一个封装过的入口,可以在 `node_modules/.modern/[entryName]/index.js` 找到真正的入口。
102
103
 
103
104
  #### 约定式路由
104
105
 
@@ -146,7 +147,7 @@ export default (App: React.ComponentType, bootstrap: () => void) => {
146
147
  // do something before bootstrap...
147
148
  initSomething().then(() => {
148
149
  bootstrap();
149
- })
150
+ });
150
151
  };
151
152
  ```
152
153
 
@@ -170,7 +171,9 @@ function render() {
170
171
  // runtime 的插件参数...
171
172
  })(App);
172
173
  if (IS_BROWSER) {
173
- customBootstrap(AppWrapper, () => bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM));
174
+ customBootstrap(AppWrapper, () =>
175
+ bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM),
176
+ );
174
177
  }
175
178
  return AppWrapper;
176
179
  }
@@ -182,9 +185,11 @@ export default AppWrapper;
182
185
 
183
186
  ### 构建模式入口
184
187
 
185
- 构建模式是指不使用任何 Modern.js 运行时的能力,完全由开发者自己定义项目 webpack 的入口。
188
+ 构建模式指的是不使用 Modern.js 自动生成的入口,而是完全由开发者自行定义页面的入口。
186
189
 
187
- 如果入口中存在 `index.[jt]sx` ,并且没有默认导出函数时,这时候该文件就是真正的 webpack 入口文件。这里和 [Create React App](https://github.com/facebook/create-react-app) 类似,需要自己将组件挂载到 DOM 节点、添加热更新代码等。例如:
190
+ 当入口目录中存在 `index.[jt]sx`,并且没有通过 `export default` 导出函数时,这类文件就会被识别为 webpack Rspack entry 模块。
191
+
192
+ 此时 Modern.js 不会自动生成入口代码,因此需要你自行将组件挂载到 DOM 节点上,例如:
188
193
 
189
194
  ```js title=src/index.jsx
190
195
  import React from 'react';
@@ -194,42 +199,39 @@ import App from './App';
194
199
  ReactDOM.render(<App />, document.getElementById('root'));
195
200
  ```
196
201
 
197
- Modern.js **不推荐**新项目使用这种方式,这种方式丧失了框架的一些能力,如 **`modern.config.js` 文件中的 `runtime` 配置将不会再生效**。但是在项目从其他框架迁移到 Modern.js,例如 CRA,或是自己手动搭建的 webpack 时,这种方式会非常有用。
202
+ 这种方式等价于开启 Modern.js [source.entries.disableMount](/configure/app/source/entries) 选项。当你使用这种方式时,**将无法使用 Modern.js 框架的运行时能力**,比如 modern.config.js 文件中的 `runtime` 配置将不会再生效。
198
203
 
199
- ## 使用配置指定入口
204
+ ## 自定义入口
200
205
 
201
- 大部分存量项目并不是按照 Modern.js 的目录结构来搭建的。如果要改成 Modern.js 约定的目录结构,会存在一定的迁移成本。
206
+ 在某些情况下,你可能需要自定义入口配置,而不是使用 Modern.js 提供的入口约定。
202
207
 
203
- 在这种情况下,除了使用文件约定生成入口外,你可以在 `modern.config.[jt]s` 中手动配置入口。
208
+ 比如你需要将一个非 Modern.js 项目迁移到 Modern.js,它并不是按照 Modern.js 的目录结构来搭建的。如果你要将它改成 Modern.js 约定的目录结构,可能会存在一定的迁移成本。这种情况下,你就可以使用自定义入口。
204
209
 
205
- ```ts title="modern.config.ts"
206
- export default defineConfig({
207
- source: {
208
- entries: {
209
- // 指定一个名称为 entry_customize 的新入口
210
- entry_customize: './src/home/test/index.ts',
211
- },
212
- // 禁用默认入口扫描
213
- disableDefaultEntries: true,
214
- },
215
- });
216
- ```
210
+ Modern.js 提供了以下配置项,你可以在 [modern.config.ts](/configure/app/usage) 中配置它们:
217
211
 
218
- ### 禁用默认入口扫描
212
+ - [source.entries](/configure/app/source/entries):用于设置自定义的入口对象。
213
+ - [source.disableDefaultEntries](/configure/app/source/disable-default-entries):用于关闭 Modern.js 默认的入口扫描行为。当你使用自定义入口时,项目的部分结构可能会恰巧命中 Modern.js 约定的目录结构,但你可能不希望 Modern.js 为你自动生成入口配置,开启该选项可以避免这个问题。
219
214
 
220
- 当使用自定义入口时,项目的部分结构可能恰巧命中了 Modern.js 的目录约定,但实际上这部分目录并不是真实的入口。
215
+ ### 示例
221
216
 
222
- Modern.js 提供了 `disableDefaultEntries` 配置,来禁用默认的入口扫描规则。当你需要自定义入口时,一般需要将 `disableDefaultEntries` 与 `entries` 结合使用。这样,一些存量项目可以在不修改目录结构的情况下,快速地进行迁移。
217
+ 下面是一个自定义入口的例子,你也可以查看相关配置项的文档来了解更多用法。
223
218
 
224
219
  ```ts title="modern.config.ts"
225
220
  export default defineConfig({
226
221
  source: {
222
+ entries: {
223
+ // 指定一个名为 'my-entry' 的入口
224
+ 'my-entry': {
225
+ // 入口模块的路径
226
+ entry: './src/my-page/index.tsx',
227
+ // 关闭 Modern.js 自动生成入口代码的行为
228
+ disableMount: true,
229
+ },
230
+ },
231
+ // 禁用入口扫描行为
227
232
  disableDefaultEntries: true,
228
233
  },
229
234
  });
230
235
  ```
231
236
 
232
- :::tip
233
- 详细用法请查看 [source.entries](/configure/app/source/entries) 和 [source.disableDefaultEntries](/configure/app/source/disable-default-entries)。
234
-
235
- :::
237
+ 注意,当你开启 `disableMount` 时,**将无法使用 Modern.js 框架的运行时能力**,比如 modern.config.ts 文件中的 `runtime` 配置将不会再生效。
@@ -92,7 +92,7 @@ $ pnpm run build
92
92
  > modern build
93
93
 
94
94
  info Staring production build...
95
- ready Client compiled in 50ms
95
+ ready Client compiled in 50 ms
96
96
  info Production file sizes:
97
97
 
98
98
  File Size Gzipped
package/package.json CHANGED
@@ -15,17 +15,17 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "0.0.0-nightly-20230920160608",
18
+ "version": "0.0.0-nightly-20230922160540",
19
19
  "publishConfig": {
20
20
  "registry": "https://registry.npmjs.org/",
21
21
  "access": "public",
22
22
  "provenance": true
23
23
  },
24
24
  "dependencies": {
25
- "@modern-js/sandpack-react": "0.0.0-nightly-20230920160608"
25
+ "@modern-js/sandpack-react": "0.0.0-nightly-20230922160540"
26
26
  },
27
27
  "peerDependencies": {
28
- "@modern-js/builder-doc": "0.0.0-nightly-20230920160608"
28
+ "@modern-js/builder-doc": "0.0.0-nightly-20230922160540"
29
29
  },
30
30
  "devDependencies": {
31
31
  "classnames": "^2",
@@ -35,12 +35,12 @@
35
35
  "ts-node": "^10.9.1",
36
36
  "typescript": "^5",
37
37
  "fs-extra": "^10",
38
- "rspress": "0.0.13",
39
- "@rspress/shared": "0.0.13",
38
+ "rspress": "0.1.1",
39
+ "@rspress/shared": "0.1.1",
40
40
  "@types/node": "^16",
41
41
  "@types/fs-extra": "^9",
42
- "@modern-js/doc-plugin-auto-sidebar": "0.0.0-nightly-20230920160608",
43
- "@modern-js/builder-doc": "0.0.0-nightly-20230920160608"
42
+ "@modern-js/builder-doc": "0.0.0-nightly-20230922160540",
43
+ "@modern-js/doc-plugin-auto-sidebar": "0.0.0-nightly-20230922160540"
44
44
  },
45
45
  "scripts": {
46
46
  "dev": "rspress dev",