@modern-js/main-doc 2.0.0-beta.4 → 2.0.0-beta.5
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/dev.md +8 -3
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/inspect.md +33 -8
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/serve.md +32 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/server.md +31 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/bootstrap.md +4 -3
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/create-app.md +2 -3
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/use-module-apps.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/components/init-app.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/builder-plugins.md +70 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/with-master-app.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/plugins.md +11 -5
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/disable-entry-dirs.md +38 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/entries.md +66 -2
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/esbuild.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/guides/concept/entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/guides/get-started/quick-start.md +3 -3
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/{concept → topic-detail/framework-plugin}/lifecycle.md +0 -0
- package/package.json +3 -3
- package/zh/apis/app/commands/dev.md +9 -4
- package/zh/apis/app/commands/inspect.md +34 -9
- package/zh/apis/app/commands/{start.md → serve.md} +3 -3
- package/zh/apis/app/hooks/src/index_.md +1 -1
- package/zh/apis/app/hooks/src/server.md +31 -0
- package/zh/apis/app/runtime/core/bootstrap.md +3 -4
- package/zh/apis/app/runtime/core/create-app.md +1 -18
- package/zh/apis/app/runtime/core/use-module-apps.md +64 -33
- package/zh/apis/app/runtime/web-server/hook.md +1 -1
- package/zh/apis/app/runtime/web-server/middleware.md +1 -0
- package/zh/components/default-mwa-generate.md +5 -0
- package/zh/components/deploy.md +1 -0
- package/zh/components/enable-micro-frontend.md +13 -0
- package/zh/components/init-app.md +2 -2
- package/zh/components/micro-runtime-config.md +18 -0
- package/zh/components/prerequisites.md +2 -2
- package/zh/components/release-note.md +1 -0
- package/zh/configure/app/builder-plugins.md +72 -0
- package/zh/configure/app/deploy/_category_.json +4 -0
- package/zh/configure/app/deploy/microFrontend.md +64 -0
- package/zh/configure/app/dev/with-master-app.md +0 -2
- package/zh/configure/app/plugins.md +10 -4
- package/zh/configure/app/runtime/master-app.md +33 -36
- package/zh/configure/app/source/disable-entry-dirs.md +37 -0
- package/zh/configure/app/source/entries-dir.md +0 -3
- package/zh/configure/app/source/entries.md +66 -3
- package/zh/guides/advanced-features/compatibility.md +12 -1
- package/zh/guides/advanced-features/eslint.md +21 -21
- package/zh/guides/advanced-features/ssg.md +14 -3
- package/zh/guides/advanced-features/ssr.md +1 -1
- package/zh/guides/advanced-features/testing.md +11 -0
- package/zh/guides/advanced-features/web-server.md +12 -1
- package/zh/guides/basic-features/css/tailwindcss.md +11 -0
- package/zh/guides/basic-features/data-fetch.md +398 -5
- package/zh/guides/basic-features/routes.md +35 -3
- package/zh/guides/concept/entries.md +104 -14
- package/zh/guides/get-started/quick-start.md +8 -5
- package/zh/guides/get-started/upgrade.md +3 -1
- package/zh/guides/{concept → topic-detail/framework-plugin}/lifecycle.md +0 -0
- package/zh/guides/topic-detail/micro-frontend/c01-introduction.md +29 -0
- package/zh/guides/topic-detail/micro-frontend/c02-development.md +191 -0
- package/zh/guides/topic-detail/micro-frontend/c03-main-app.md +246 -0
- package/zh/guides/topic-detail/micro-frontend/c04-communicate.md +54 -0
- package/zh/guides/topic-detail/micro-frontend/{mixed-stack.md → c05-mixed-stack.md} +3 -3
- package/zh/guides/topic-detail/monorepo/create-sub-project.md +2 -2
- package/zh/tutorials/first-app/c01-start.md +9 -4
- package/zh/tutorials/first-app/c03-css.md +19 -0
- package/zh/tutorials/first-app/c04-routes.md +4 -4
- package/zh/tutorials/first-app/c05-loader.md +3 -3
- package/zh/tutorials/first-app/c06-model.md +19 -19
- package/zh/tutorials/first-app/c07-container.md +38 -23
- package/zh/tutorials/first-app/c08-entries.md +4 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/start.md +0 -32
- package/zh/guides/advanced-features/custom-app.md +0 -70
- package/zh/guides/topic-detail/micro-frontend/communicate.md +0 -39
- package/zh/guides/topic-detail/micro-frontend/debugging.md +0 -168
- package/zh/guides/topic-detail/micro-frontend/introduction.md +0 -13
- package/zh/guides/topic-detail/micro-frontend/route-mode.md +0 -110
package/.turbo/turbo-build.log
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
sidebar_position: 1
|
3
3
|
---
|
4
4
|
|
5
|
-
# dev
|
5
|
+
# dev / start
|
6
6
|
|
7
7
|
```bash
|
8
|
-
Usage: modern dev [options]
|
8
|
+
Usage: modern dev / modern start [options]
|
9
9
|
|
10
10
|
Development commands
|
11
11
|
|
@@ -19,8 +19,13 @@ Options:
|
|
19
19
|
|
20
20
|
`modern dev` start a development server,watch file change,default support React Fast Refresh:
|
21
21
|
|
22
|
+
`modern start` is an alias of `modern dev` command, the usage of the two are exactly the same.
|
23
|
+
|
22
24
|
```bash
|
23
|
-
|
25
|
+
$ modern dev
|
26
|
+
|
27
|
+
info Starting dev server...
|
28
|
+
info App running at:
|
24
29
|
|
25
30
|
> Local: http://localhost:8080/
|
26
31
|
> Network: http://192.168.0.1:8080/
|
@@ -5,31 +5,56 @@ sidebar_position: 7
|
|
5
5
|
```
|
6
6
|
Usage: modern inspect [options]
|
7
7
|
|
8
|
-
inspect internal webpack config
|
9
|
-
|
10
8
|
Options:
|
11
9
|
--env <env> view the configuration in the target environment (default: "development")
|
12
10
|
--output <output> Specify the path to output in the dist (default: "/")
|
13
|
-
--no-console Do not output the full result in shell
|
14
11
|
--verbose Show the full function in the result
|
15
12
|
-c --config <config> configuration file path, which can be a relative path or an absolute path
|
16
13
|
-h, --help show command help
|
17
14
|
```
|
18
15
|
|
19
|
-
`modern inspect` command used to view the
|
16
|
+
`modern inspect` command used to view the [Modern.js Builder config](https://modernjs.dev/builder/en/guide/basic/builder-config.html) and webpack config of the project.
|
17
|
+
|
18
|
+
After executing the command `npx modern inspect` in the project root directory, the following files will be generated in the `dist` directory of the project:
|
19
|
+
|
20
|
+
- `builder.config.js`: The Modern.js Builder config to use at build time.
|
21
|
+
- `webpack.config.web.js`: The webpack config used by to use at build time.
|
22
|
+
|
23
|
+
```bash
|
24
|
+
➜ npx modern inspect
|
25
|
+
|
26
|
+
Inspect config succeed, open following files to view the content:
|
20
27
|
|
21
|
-
|
28
|
+
- Builder Config: /root/my-project/dist/builder.config.js
|
29
|
+
- Webpack Config (web): /root/my-project/dist/webpack.config.web.js
|
30
|
+
```
|
22
31
|
|
23
32
|
## Configuration Env
|
24
33
|
|
25
|
-
By default, the
|
34
|
+
By default, the inspect command will output the development configs, you can use the `--env production` option to output the production configs:
|
26
35
|
|
27
36
|
```bash
|
28
37
|
modern inspect --env production
|
29
38
|
```
|
30
39
|
|
31
|
-
##
|
40
|
+
## Verbose content
|
41
|
+
|
42
|
+
By default, the inspect command will omit the function content in the config object, you can use the `--verbose` option to output the full content of the function:
|
43
|
+
|
44
|
+
```bash
|
45
|
+
modern inspect --verbose
|
46
|
+
```
|
32
47
|
|
33
48
|
### SSR Configuration
|
34
49
|
|
35
|
-
If the project has SSR
|
50
|
+
If the project has enabled SSR, an additional `webpack.config.node.js` file will be generated in the `dist/`, corresponding to the webpack configuration at SSR build time.
|
51
|
+
|
52
|
+
```bash
|
53
|
+
➜ npx modern inspect
|
54
|
+
|
55
|
+
Inspect config succeed, open following files to view the content:
|
56
|
+
|
57
|
+
- Builder Config: /root/my-project/dist/builder.config.js
|
58
|
+
- Webpack Config (web): /root/my-project/dist/webpack.config.web.js
|
59
|
+
- Webpack Config (node): /root/my-project/dist/webpack.config.node.js
|
60
|
+
```
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 6
|
3
|
+
---
|
4
|
+
|
5
|
+
```bash
|
6
|
+
Usage: modern serve [options]
|
7
|
+
|
8
|
+
run server
|
9
|
+
|
10
|
+
Options:
|
11
|
+
-c --config <config> configuration file path, which can be a relative path or an absolute path
|
12
|
+
-h, --help show command help
|
13
|
+
--api-only only run API service
|
14
|
+
```
|
15
|
+
|
16
|
+
Usually use the `modern serve` command to enable project run in the production environment, and you need to execute the [`build'](/docs/apis/app/commands/build) command in advance to build the product.
|
17
|
+
|
18
|
+
By default, the project will run in `localhost:8080`, you can modify the Server port number with `server.port`:
|
19
|
+
|
20
|
+
```js
|
21
|
+
export default defineConfig({
|
22
|
+
server: {
|
23
|
+
port: 8081,
|
24
|
+
}
|
25
|
+
})
|
26
|
+
```
|
27
|
+
|
28
|
+
import CommandTip from '@site-docs-en/components/command-tip.md'
|
29
|
+
|
30
|
+
<CommandTip />
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
title: "*.[server|node].[tj]sx"
|
3
|
+
sidebar_position: 8
|
4
|
+
---
|
5
|
+
|
6
|
+
Used in application projects to place server side code, it generally has the following two functions:
|
7
|
+
|
8
|
+
1. When `*.tsx` and `*. [server|node].tsx` coexist, rendering on the server side will give preference to the `*. [server|node].tsx` file instead of the `*.tsx` file.
|
9
|
+
|
10
|
+
2. When using [data loader](/docs/guides/basic-features/data-fetch), the server-side dependencies need to be re-exported from this file
|
11
|
+
|
12
|
+
```tsx
|
13
|
+
// routes/user/avatar.tsx
|
14
|
+
import { useLoaderData } from '@modern-js/runtime/router';
|
15
|
+
import { readFile } from './utils.server';
|
16
|
+
|
17
|
+
type ProfileData = { /* some type declarations */ }
|
18
|
+
|
19
|
+
export const loader = async(): ProfileData => {
|
20
|
+
const profile = await readFile('profile.json');
|
21
|
+
return profile;
|
22
|
+
}
|
23
|
+
|
24
|
+
export default function UserPage() {
|
25
|
+
const profileData = useLoaderData() as ProfileData;
|
26
|
+
return <div>{profileData}</div>;
|
27
|
+
}
|
28
|
+
|
29
|
+
// routes/user/utils.server.ts
|
30
|
+
export * from 'fs-extra';
|
31
|
+
```
|
@@ -2,7 +2,7 @@
|
|
2
2
|
title: bootstrap
|
3
3
|
---
|
4
4
|
|
5
|
-
Used to start and mount App, usually without manual calls。This API is only required when using [Custom App](/docs/guides/
|
5
|
+
Used to start and mount App, usually without manual calls。This API is only required when using [Custom App](/docs/guides/concept/entries#自定义-app).
|
6
6
|
|
7
7
|
## Usage
|
8
8
|
|
@@ -41,7 +41,6 @@ type BootStrap<T = unknown> = (
|
|
41
41
|
```tsx
|
42
42
|
import ReactDOM from 'react-dom/client'
|
43
43
|
import { createApp, bootstrap } from '@modern-js/runtime';
|
44
|
-
import { router, state } from '@modern-js/runtime/plugins';
|
45
44
|
|
46
45
|
function App() {
|
47
46
|
return <div>Hello Modern.js</div>;
|
@@ -49,7 +48,9 @@ function App() {
|
|
49
48
|
|
50
49
|
const WrappedApp = createApp({
|
51
50
|
// customized plugin
|
52
|
-
plugins: [
|
51
|
+
plugins: [
|
52
|
+
customPlugin(),
|
53
|
+
],
|
53
54
|
})(App);
|
54
55
|
|
55
56
|
bootstrap(WrappedApp, 'root', undefined, ReactDOM);
|
@@ -2,7 +2,7 @@
|
|
2
2
|
title: createApp
|
3
3
|
---
|
4
4
|
|
5
|
-
Used to create custom entries, custom runtime plugins. This API is only required when using [Custom App](/docs/guides/
|
5
|
+
Used to create custom entries, custom runtime plugins. This API is only required when using [Custom App](/docs/guides/concept/entries#自定义-app).
|
6
6
|
|
7
7
|
## Usage
|
8
8
|
|
@@ -40,8 +40,7 @@ function App() {
|
|
40
40
|
|
41
41
|
export default createApp({
|
42
42
|
plugins: [
|
43
|
-
|
44
|
-
state({}),
|
43
|
+
customPlugin()
|
45
44
|
]
|
46
45
|
})(App);
|
47
46
|
```
|
@@ -15,7 +15,7 @@ After create the project, Modern.js automatically installs dependency and create
|
|
15
15
|
You can run the following command in the directory of the new project:
|
16
16
|
pnpm run dev # Run and debug the project according to the requirements of the development environment
|
17
17
|
pnpm run build # Build the project according to the requirements of the product environment
|
18
|
-
pnpm run
|
18
|
+
pnpm run serve # Run the project according to the requirements of the product environment
|
19
19
|
pnpm run lint # Check and fix all codes
|
20
20
|
pnpm run new # Create more project elements, such as application portals
|
21
21
|
```
|
@@ -0,0 +1,70 @@
|
|
1
|
+
---
|
2
|
+
title: builderPlugins
|
3
|
+
sidebar_position: 10
|
4
|
+
---
|
5
|
+
|
6
|
+
- Type: `BuilderPlugin[]`
|
7
|
+
- Default: `[]`
|
8
|
+
|
9
|
+
Used to configure the Modern.js Builder plugin.
|
10
|
+
|
11
|
+
Modern.js Builder is the build engine of Modern.js, please read [Builder](/docs/guides/basic-features/builder) for background. If you want to know how to write Builder plugins, you can refer to [Modern.js Builder - Introduce to Plugin](https://modernjs.dev/builder/en/plugins/introduction.html).
|
12
|
+
|
13
|
+
## Precautions
|
14
|
+
|
15
|
+
This option **is used to configure the Modern.js Builder plugins**. If you need to configure other types of plugins, please select the corresponding configs:
|
16
|
+
|
17
|
+
- Use [plugins](docs/configure/app/builder-plugins) to configure Modern.js framework plugins.
|
18
|
+
- Use [tools.webpack](/docs/configure/app/tools/webpack) or [tools.webpackChain](/docs/configure/app/tools/webpack-chain) to configure webpack plugins.
|
19
|
+
- Use [tools.babel](/docs/configure/app/tools/babel) to configure babel plugins.
|
20
|
+
|
21
|
+
## When to use
|
22
|
+
|
23
|
+
In most scenarios, we recommend you to use the Modern.js framework plugin, which can be registered through the [plugins](docs/configure/app/plugins) config. Because the API provided by the framework plugin is richer and more capable, while the API provided by the Builder plugin can only be used to build scenes.
|
24
|
+
|
25
|
+
When you need to reference some existing Builder plugins (and there is no related capability in Modern.js), or reuse Builder plugins between different frameworks, you can use the `builderPlugins` field to register them.
|
26
|
+
|
27
|
+
## Example
|
28
|
+
|
29
|
+
Below is an example of using the Builder plugin.
|
30
|
+
|
31
|
+
### Using plugins on npm
|
32
|
+
|
33
|
+
To use a plugin on npm, you need to install the plugin through the package manager and import it.
|
34
|
+
|
35
|
+
```ts title="modern.config.ts"
|
36
|
+
import MyBuilderPlugin from 'my-builder-plugin';
|
37
|
+
|
38
|
+
export default defineConfig({
|
39
|
+
builderPlugins: [MyBuilderPlugin()],
|
40
|
+
});
|
41
|
+
```
|
42
|
+
|
43
|
+
### Using local plugins
|
44
|
+
|
45
|
+
Use the plugin in the local code repository, you can import it directly through the relative path import.
|
46
|
+
|
47
|
+
```ts title="modern.config.ts"
|
48
|
+
import MyBuilderPlugin from './plugin/myBuilderPlugin';
|
49
|
+
|
50
|
+
export default defineConfig({
|
51
|
+
builderPlugins: [MyBuilderPlugin()],
|
52
|
+
});
|
53
|
+
```
|
54
|
+
|
55
|
+
### Plugin configuration items
|
56
|
+
|
57
|
+
If the plugin provides some custom configuration options, you can pass in the configuration through the parameters of the plugin function.
|
58
|
+
|
59
|
+
```ts title="modern.config.ts"
|
60
|
+
import MyBuilderPlugin from 'my-builder-plugin';
|
61
|
+
|
62
|
+
export default defineConfig({
|
63
|
+
builderPlugins: [
|
64
|
+
MyBuilderPlugin({
|
65
|
+
foo: 1,
|
66
|
+
bar: 2,
|
67
|
+
}),
|
68
|
+
],
|
69
|
+
});
|
70
|
+
```
|
@@ -29,4 +29,3 @@ export default defineConfig({
|
|
29
29
|
- moduleApp: `string` Online address of the main application.
|
30
30
|
- moduleName: `Contact` The name of the child app (needs to match the module name registered in the main app)。
|
31
31
|
|
32
|
-
For detailed usage, please refer to [Micro Front-end Sub-Application](/docs/guides/topic-detail/micro-frontend/debugging)。
|
@@ -3,18 +3,24 @@ title: plugins
|
|
3
3
|
sidebar_position: 9
|
4
4
|
---
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
- Type: `CliPlugin[]`
|
7
|
+
- Default: `[]`
|
8
8
|
|
9
|
-
Used to configure custom Modern.js plugins.
|
9
|
+
Used to configure custom Modern.js framework plugins.
|
10
10
|
|
11
11
|
For the way to write custom plugins, please refer to [How to Write Plugins](/docs/guides/topic-detail/framework-plugin/implement).
|
12
12
|
|
13
|
-
|
13
|
+
## Precautions
|
14
|
+
|
15
|
+
This config **is used to configure the Modern.js framework plugin**. If you need to configure other types of plugins, please select the corresponding configs:
|
16
|
+
|
17
|
+
- Use [builderPlugins](docs/configure/app/builder-plugins) to configure Modern.js Builder plugins.
|
18
|
+
- Use [tools.webpack](/docs/configure/app/tools/webpack) or [tools.webpackChain](/docs/configure/app/tools/webpack-chain) to configure webpack plugins.
|
19
|
+
- Use [tools.babel](/docs/configure/app/tools/babel) to configure babel plugins.
|
14
20
|
|
15
21
|
## Plugin type
|
16
22
|
|
17
|
-
There are three different
|
23
|
+
There are three different type of framework plugins built into the Modern.js:
|
18
24
|
|
19
25
|
- `CLI Plugin`,for local development, compilation and build phases, can extend various capabilities on the command line and compilation phases.
|
20
26
|
- `Server Plugin`,for server-level.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
---
|
2
|
+
title: source.disableEntryDirs
|
3
|
+
|
4
|
+
sidebar_label: disableEntryDirs
|
5
|
+
---
|
6
|
+
|
7
|
+
* Type: `string[]`
|
8
|
+
* Default: `[]`
|
9
|
+
|
10
|
+
By default, application entries are identified based on the'src 'directory, you can disable some directories from being identified as application entries with this option.
|
11
|
+
|
12
|
+
For example, when the configuration and directory structure is as follows:
|
13
|
+
|
14
|
+
|
15
|
+
```typescript title="modern.config.ts"
|
16
|
+
export default defineConfig({
|
17
|
+
source: {
|
18
|
+
disableEntryDirs: './src/one'
|
19
|
+
}
|
20
|
+
})
|
21
|
+
```
|
22
|
+
|
23
|
+
``` title="Project directory structure"
|
24
|
+
└── src/
|
25
|
+
├── one/
|
26
|
+
| └── App.tsx
|
27
|
+
├── two/
|
28
|
+
| └── routes/
|
29
|
+
└── env.d.ts
|
30
|
+
```
|
31
|
+
|
32
|
+
When this option is not set, Modern.js will generate two entries based on the project directory:
|
33
|
+
- one
|
34
|
+
- two
|
35
|
+
|
36
|
+
When this option is set, `src/one` will not be recognized as an entry directory.
|
37
|
+
|
38
|
+
A common usage is to configure the `src/common`, `src/components` directories to this option to avoid these directories being recognized as application entries.
|
@@ -27,10 +27,34 @@ export default defineConfig({
|
|
27
27
|
});
|
28
28
|
```
|
29
29
|
|
30
|
-
|
30
|
+
By default, the configured entry is equivalent to `App.[jt]sx`, that is, the specified entry file only needs to export the root component of the application.
|
31
31
|
|
32
|
-
|
32
|
+
For example the following directory structure:
|
33
33
|
|
34
|
+
```bash
|
35
|
+
.
|
36
|
+
├── src
|
37
|
+
│ └── entry
|
38
|
+
│ ├── chat.tsx
|
39
|
+
│ └── home.tsx
|
40
|
+
└── package.json
|
41
|
+
```
|
42
|
+
|
43
|
+
With the content of the above default entry mechanism, Modern.js when analyzing the above directory, will not get any default entry.
|
44
|
+
|
45
|
+
In cases where you do not want to change the directory structure (such as project migration), you can customize the entry through `source.entries`:
|
46
|
+
|
47
|
+
|
48
|
+
```ts title="modern.config.js"
|
49
|
+
export default defineConfig({
|
50
|
+
source: {
|
51
|
+
entries: {
|
52
|
+
home: './src/entry/home.tsx',
|
53
|
+
chat: './src/entry/chat.tsx',
|
54
|
+
},
|
55
|
+
},
|
56
|
+
});
|
57
|
+
```
|
34
58
|
|
35
59
|
## Object
|
36
60
|
|
@@ -60,3 +84,43 @@ export default defineConfig({
|
|
60
84
|
},
|
61
85
|
});
|
62
86
|
```
|
87
|
+
|
88
|
+
By default, the configured entry is equivalent to `App.[jt]sx`. If you want the entry to be equivalent to the entry in build mode, you can set the value to'Object' and the property `disableMount` to `true`.
|
89
|
+
|
90
|
+
## Combine Entry
|
91
|
+
|
92
|
+
When `source.entries` is specified, the Modern.js merges the user-defined entry with the default entry obtained by analyzing the directory structure. The merging rule is:
|
93
|
+
|
94
|
+
Compare the entry path set by the custom entry with the default entry path. When the entry paths are the same, the custom entry will override the default entry.
|
95
|
+
|
96
|
+
For example the following directory structure:
|
97
|
+
|
98
|
+
|
99
|
+
```bash
|
100
|
+
.
|
101
|
+
├── src
|
102
|
+
│ ├── chat
|
103
|
+
│ │ └── App.jsx
|
104
|
+
│ └── home
|
105
|
+
│ └── index.js
|
106
|
+
└── package.json
|
107
|
+
```
|
108
|
+
|
109
|
+
Modern.js analyze the `src/` directory to get the default entries `chat` and `home`. When the user configures the following in the `modern.config.js` file:
|
110
|
+
|
111
|
+
```ts title="modern.config.ts"
|
112
|
+
import { defineConfig } from '@modern-js/app-tools';
|
113
|
+
|
114
|
+
export default defineConfig({
|
115
|
+
source: {
|
116
|
+
entries: {
|
117
|
+
index: './src/home/index.js',
|
118
|
+
},
|
119
|
+
},
|
120
|
+
};
|
121
|
+
```
|
122
|
+
|
123
|
+
You can see that the path of the custom entry `index` is the same as the path of the default entry `home`. During the merging process, `index` will override `home`, and the final entry is as follows:
|
124
|
+
|
125
|
+
- `chat -> ./src/chat/App.jsx`
|
126
|
+
- `index -> ./src/home/index.js`
|
@@ -35,4 +35,4 @@ export default defineConfig({
|
|
35
35
|
});
|
36
36
|
```
|
37
37
|
|
38
|
-
For config details, please refer to [Modern.js Builder -
|
38
|
+
For config details, please refer to [Modern.js Builder - Esbuild Plugin Configuration](https://modernjs.dev/builder/en/plugins/plugin-esbuild.html#config).
|
@@ -105,7 +105,7 @@ Typically, the above two modes are sufficient, but when developers need to take
|
|
105
105
|
|
106
106
|
If the entry is the `index.[jt]sx?` convention, the Modern.js determines the build behavior based on whether the file has a default component export.
|
107
107
|
|
108
|
-
For details, please refer to [customized App](/docs/guides/
|
108
|
+
For details, please refer to [customized App](/docs/guides/concept/entries#自定义-app).
|
109
109
|
|
110
110
|
## configuration
|
111
111
|
|
@@ -140,12 +140,12 @@ The bundle is generated to `dist/` by default, and the directory structure is as
|
|
140
140
|
|
141
141
|
## Verify
|
142
142
|
|
143
|
-
Execute `pnpm run
|
143
|
+
Execute `pnpm run serve` in the project to verify locally that the bundle is running correctly:
|
144
144
|
|
145
145
|
```bash
|
146
|
-
$ pnpm run
|
146
|
+
$ pnpm run serve
|
147
147
|
|
148
|
-
> modern
|
148
|
+
> modern serve
|
149
149
|
|
150
150
|
Starting the modern server...
|
151
151
|
info App running at:
|
File without changes
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "2.0.0-beta.
|
14
|
+
"version": "2.0.0-beta.5",
|
15
15
|
"publishConfig": {
|
16
16
|
"registry": "https://registry.npmjs.org/",
|
17
17
|
"access": "public"
|
@@ -20,11 +20,11 @@
|
|
20
20
|
"@modern-js/builder-doc": "2.0.0-beta.4"
|
21
21
|
},
|
22
22
|
"devDependencies": {
|
23
|
+
"@modern-js/builder-doc": "2.0.0-beta.4",
|
23
24
|
"ts-node": "^10",
|
24
25
|
"fs-extra": "^10",
|
25
26
|
"@types/node": "^16",
|
26
|
-
"@types/fs-extra": "^9"
|
27
|
-
"@modern-js/builder-doc": "2.0.0-beta.4"
|
27
|
+
"@types/fs-extra": "^9"
|
28
28
|
},
|
29
29
|
"scripts": {
|
30
30
|
"build": "npx ts-node ./scripts/sync.ts"
|
@@ -2,10 +2,10 @@
|
|
2
2
|
sidebar_position: 1
|
3
3
|
---
|
4
4
|
|
5
|
-
# dev
|
5
|
+
# dev / start
|
6
6
|
|
7
7
|
```bash
|
8
|
-
Usage: modern dev [options]
|
8
|
+
Usage: modern dev / modern start [options]
|
9
9
|
|
10
10
|
本地开发命令
|
11
11
|
|
@@ -17,10 +17,15 @@ Options:
|
|
17
17
|
--api-only 仅启动 API 接口服务
|
18
18
|
```
|
19
19
|
|
20
|
-
`modern dev`
|
20
|
+
`modern dev` 命令用于启动一个本地开发服务器,对源代码进行开发环境编译,同时监听源文件变化,默认支持模块热更新和 React Fast Refresh。
|
21
|
+
|
22
|
+
`modern start` 是 `modern dev` 命令的别名,两者的功能和用法完全一致。
|
21
23
|
|
22
24
|
```bash
|
23
|
-
|
25
|
+
$ modern dev
|
26
|
+
|
27
|
+
info Starting dev server...
|
28
|
+
info App running at:
|
24
29
|
|
25
30
|
> Local: http://localhost:8080/
|
26
31
|
> Network: http://192.168.0.1:8080/
|
@@ -5,31 +5,56 @@ sidebar_position: 7
|
|
5
5
|
```
|
6
6
|
Usage: modern inspect [options]
|
7
7
|
|
8
|
-
inspect internal webpack config
|
9
|
-
|
10
8
|
Options:
|
11
9
|
--env <env> 查看指定环境下的配置 (default: "development")
|
12
10
|
--output <output> 指定在 dist 目录下输出的路径 (default: "/")
|
13
|
-
--no-console 不在终端中输出完整结果
|
14
11
|
--verbose 在结果中展示函数的完整内容
|
15
12
|
-c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
|
16
13
|
-h, --help 显示命令帮助
|
17
14
|
```
|
18
15
|
|
19
|
-
`modern inspect` 命令,用于查看项目的 webpack
|
16
|
+
`modern inspect` 命令,用于查看项目的 [Modern.js Builder 配置](https://modernjs.dev/builder/zh/guide/basic/builder-config.html) 以及 webpack 配置。
|
17
|
+
|
18
|
+
在项目根目录下执行命令 `npx modern inspect` 后,会在项目的 `dist` 目录生成以下文件:
|
19
|
+
|
20
|
+
- `builder.config.js`: 表示在构建时使用的 Modern.js Builder 配置。
|
21
|
+
- `webpack.config.web.js`: 表示在构建时使用的 webpack 配置。
|
22
|
+
|
23
|
+
```bash
|
24
|
+
➜ npx modern inspect
|
25
|
+
|
26
|
+
Inspect config succeed, open following files to view the content:
|
20
27
|
|
21
|
-
|
28
|
+
- Builder Config: /root/my-project/dist/builder.config.js
|
29
|
+
- Webpack Config (web): /root/my-project/dist/webpack.config.web.js
|
30
|
+
```
|
22
31
|
|
23
32
|
## 指定环境
|
24
33
|
|
25
|
-
|
34
|
+
默认情况下,inspect 命令会输出开发环境的配置,你可以添加 `--env production` 选项来输出生产环境的配置:
|
26
35
|
|
27
36
|
```bash
|
28
37
|
modern inspect --env production
|
29
38
|
```
|
30
39
|
|
31
|
-
##
|
40
|
+
## 完整内容
|
41
|
+
|
42
|
+
默认情况下,inspect 命令会省略配置对象中的函数内容,你可以添加 `--verbose` 选项来输出函数的完整内容:
|
43
|
+
|
44
|
+
```bash
|
45
|
+
modern inspect --verbose
|
46
|
+
```
|
47
|
+
|
48
|
+
## SSR 构建配置
|
32
49
|
|
33
|
-
|
50
|
+
如果项目开启了 SSR 能力,则在 `dist` 目录会另外生成一份 `webpack.config.node.js` 文件,对应 SSR 构建时的 webpack 配置。
|
34
51
|
|
35
|
-
|
52
|
+
```bash
|
53
|
+
➜ npx modern inspect
|
54
|
+
|
55
|
+
Inspect config succeed, open following files to view the content:
|
56
|
+
|
57
|
+
- Builder Config: /root/my-project/dist/builder.config.js
|
58
|
+
- Webpack Config (web): /root/my-project/dist/webpack.config.web.js
|
59
|
+
- Webpack Config (node): /root/my-project/dist/webpack.config.node.js
|
60
|
+
```
|
@@ -3,9 +3,9 @@ sidebar_position: 6
|
|
3
3
|
---
|
4
4
|
|
5
5
|
```bash
|
6
|
-
Usage: modern
|
6
|
+
Usage: modern serve [options]
|
7
7
|
|
8
|
-
|
8
|
+
run server
|
9
9
|
|
10
10
|
Options:
|
11
11
|
-c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
|
@@ -13,7 +13,7 @@ Options:
|
|
13
13
|
--api-only 仅启动 API 接口服务
|
14
14
|
```
|
15
15
|
|
16
|
-
通常使用 `modern
|
16
|
+
通常使用 `modern serve` 命令在生产环境下启用应用工程, 需要提前执行 [`build`](/docs/apis/app/commands/build) 命令构建出对应产物。
|
17
17
|
|
18
18
|
默认情况下,应用将会在 `localhost:8080` 启动,可以通过 `server.port` 修改 Server 端口号:
|
19
19
|
|
@@ -13,7 +13,7 @@ sidebar_position: 3
|
|
13
13
|
|
14
14
|
```js title=src/index.js
|
15
15
|
import ReactDOM from 'react-dom/client';
|
16
|
-
import { bootstrap } from '@
|
16
|
+
import { bootstrap } from '@modern-js/runtime';
|
17
17
|
|
18
18
|
export default (App: React.ComponentType) => {
|
19
19
|
// do something before bootstrap...
|