@modern-js/main-doc 2.34.0 → 2.35.1
Sign up to get free protection for your applications and to get access to all the features.
- package/docs/en/apis/app/commands.mdx +12 -11
- package/docs/en/apis/app/hooks/config/public.mdx +2 -2
- package/docs/en/apis/app/hooks/config/upload.mdx +3 -3
- package/docs/en/components/debug-app.mdx +1 -3
- package/docs/en/components/global-proxy-config.mdx +4 -13
- package/docs/en/components/global-proxy.mdx +2 -4
- package/docs/en/components/init-app.mdx +1 -1
- package/docs/en/components/tech-stack-node-framework.mdx +1 -0
- package/docs/en/configure/app/builder-plugins.mdx +2 -2
- package/docs/en/configure/app/plugins.mdx +3 -4
- package/docs/en/configure/app/server/base-url.mdx +0 -2
- package/docs/en/configure/app/source/config-dir.mdx +2 -2
- package/docs/en/configure/app/source/enable-async-entry.mdx +1 -1
- package/docs/en/guides/advanced-features/eslint.mdx +1 -1
- package/docs/en/guides/basic-features/alias.mdx +12 -51
- package/docs/en/guides/basic-features/css.mdx +35 -15
- package/docs/en/guides/basic-features/data-fetch.mdx +12 -12
- package/docs/en/guides/basic-features/env-vars.mdx +1 -1
- package/docs/en/guides/basic-features/html.mdx +2 -2
- package/docs/en/guides/basic-features/routes.mdx +31 -19
- package/docs/en/guides/concept/builder.mdx +1 -1
- package/docs/en/guides/get-started/glossary.mdx +1 -1
- package/docs/en/guides/get-started/introduction.mdx +21 -1
- package/docs/en/guides/get-started/quick-start.mdx +8 -17
- package/docs/en/guides/get-started/tech-stack.mdx +138 -0
- package/docs/en/guides/get-started/upgrade.mdx +10 -4
- package/docs/en/guides/topic-detail/changesets/add.mdx +1 -1
- package/docs/en/guides/topic-detail/changesets/changelog.mdx +3 -3
- package/docs/en/guides/topic-detail/changesets/commit.mdx +3 -3
- package/docs/en/guides/topic-detail/changesets/release-note.mdx +3 -3
- package/docs/en/guides/topic-detail/changesets/release.mdx +1 -1
- package/docs/en/guides/topic-detail/framework-plugin/implement.mdx +6 -4
- package/docs/en/guides/topic-detail/generator/create/use.mdx +1 -9
- package/docs/en/guides/topic-detail/generator/plugin/context.md +1 -1
- package/docs/en/guides/topic-detail/micro-frontend/c01-introduction.mdx +1 -0
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +24 -17
- package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +51 -37
- package/docs/en/guides/topic-detail/micro-frontend/c04-communicate.mdx +1 -0
- package/docs/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +1 -1
- package/docs/en/tutorials/first-app/c02-component.mdx +4 -3
- package/docs/zh/apis/app/commands.mdx +10 -9
- package/docs/zh/apis/app/hooks/api/api.mdx +2 -1
- package/docs/zh/apis/app/hooks/server/index_.mdx +2 -1
- package/docs/zh/community/blog/2022-0708-updates.md +4 -4
- package/docs/zh/community/blog/overview.md +1 -1
- package/docs/zh/components/debug-app.mdx +1 -3
- package/docs/zh/components/global-proxy-config.mdx +4 -13
- package/docs/zh/components/global-proxy.mdx +2 -4
- package/docs/zh/components/tech-stack-node-framework.mdx +1 -0
- package/docs/zh/configure/app/builder-plugins.mdx +1 -1
- package/docs/zh/configure/app/plugins.mdx +1 -2
- package/docs/zh/configure/app/server/base-url.mdx +0 -2
- package/docs/zh/configure/app/source/enable-async-entry.mdx +1 -1
- package/docs/zh/guides/advanced-features/eslint.mdx +1 -1
- package/docs/zh/guides/basic-features/alias.mdx +12 -51
- package/docs/zh/guides/basic-features/css.mdx +35 -15
- package/docs/zh/guides/basic-features/data-fetch.mdx +11 -12
- package/docs/zh/guides/basic-features/html.mdx +4 -5
- package/docs/zh/guides/basic-features/routes.mdx +26 -19
- package/docs/zh/guides/get-started/introduction.mdx +20 -0
- package/docs/zh/guides/get-started/quick-start.mdx +8 -17
- package/docs/zh/guides/get-started/tech-stack.mdx +138 -0
- package/docs/zh/guides/get-started/upgrade.mdx +10 -4
- package/docs/zh/guides/topic-detail/changesets/add.mdx +1 -1
- package/docs/zh/guides/topic-detail/changesets/changelog.mdx +3 -3
- package/docs/zh/guides/topic-detail/changesets/commit.mdx +3 -3
- package/docs/zh/guides/topic-detail/changesets/release-note.mdx +3 -3
- package/docs/zh/guides/topic-detail/changesets/release.mdx +1 -1
- package/docs/zh/guides/topic-detail/framework-plugin/hook-list.mdx +1 -1
- package/docs/zh/guides/topic-detail/framework-plugin/implement.mdx +7 -5
- package/docs/zh/guides/topic-detail/generator/create/use.mdx +0 -8
- package/docs/zh/guides/topic-detail/generator/plugin/context.md +1 -1
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +45 -21
- package/docs/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +51 -33
- package/docs/zh/guides/topic-detail/micro-frontend/c04-communicate.mdx +1 -0
- package/docs/zh/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +1 -0
- package/docs/zh/tutorials/first-app/c02-component.mdx +4 -3
- package/package.json +7 -7
@@ -2,13 +2,14 @@
|
|
2
2
|
sidebar_position: 3
|
3
3
|
title: Develop Main App
|
4
4
|
---
|
5
|
+
|
5
6
|
# Develop Main App
|
6
7
|
|
7
8
|
In the previous [Experience micro frontend](/guides/topic-detail/micro-frontend/c02-development), an example was used to demonstrate how to create and configure micro frontend sub-applications. Through this chapter, you can further understand how to develop the main application, and its common configuration.
|
8
9
|
|
9
|
-
After creating an
|
10
|
+
After creating an Modern.js project through the `@modern-js/create` command, you can execute `pnpm run new` in the project (the `modern new` command is actually executed). After selecting the 「micro frontend」 mode, the micro frontend will be installed. Dependencies, just register the plugin manually.
|
10
11
|
|
11
|
-
import EnableMicroFrontend from
|
12
|
+
import EnableMicroFrontend from '@site-docs-en/components/enable-micro-frontend';
|
12
13
|
|
13
14
|
<EnableMicroFrontend />
|
14
15
|
|
@@ -26,7 +27,7 @@ It can be configured at runtime via the API [defineConfig](/apis/app/runtime/app
|
|
26
27
|
When the parameter is a function, it cannot be serialized to the output code, so please configure it through defineConfig when it comes to configuration such as functions
|
27
28
|
:::
|
28
29
|
|
29
|
-
import MicroRuntimeConfig from
|
30
|
+
import MicroRuntimeConfig from '@site-docs-en/components/micro-runtime-config';
|
30
31
|
|
31
32
|
<MicroRuntimeConfig />
|
32
33
|
|
@@ -40,15 +41,18 @@ defineConfig(App, {
|
|
40
41
|
manifest: {
|
41
42
|
getAppList: async () => {
|
42
43
|
// get from remote api
|
43
|
-
return [
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
return [
|
45
|
+
{
|
46
|
+
name: 'Table',
|
47
|
+
entry: 'http://localhost:8001',
|
48
|
+
// activeWhen: '/table'
|
49
|
+
},
|
50
|
+
{
|
51
|
+
name: 'Dashboard',
|
52
|
+
entry: 'http://localhost:8002',
|
53
|
+
// activeWhen: '/dashboard'
|
54
|
+
},
|
55
|
+
];
|
52
56
|
},
|
53
57
|
},
|
54
58
|
},
|
@@ -77,16 +81,30 @@ Suppose our subapp list is configured as follows:
|
|
77
81
|
```js title="App.tsx"
|
78
82
|
import { useModuleApps } from '@modern-js/plugin-garfish/runtime';
|
79
83
|
|
80
|
-
import {
|
84
|
+
import {
|
85
|
+
RouterProvider,
|
86
|
+
Route,
|
87
|
+
createBrowserRouter,
|
88
|
+
createRoutesFromElements,
|
89
|
+
BrowserRouter,
|
90
|
+
Link,
|
91
|
+
Outlet,
|
92
|
+
} from '@modern-js/runtime/router';
|
81
93
|
|
82
94
|
const AppLayout = () => (
|
83
95
|
<>
|
84
|
-
<div
|
85
|
-
|
86
|
-
|
96
|
+
<div>
|
97
|
+
<Link to={'/table'}>load file-based sub-app</Link>
|
98
|
+
</div>
|
99
|
+
<div>
|
100
|
+
<Link to={'/dashboard'}>load self-controlled sub-app</Link>
|
101
|
+
</div>
|
102
|
+
<div>
|
103
|
+
<Link to={'/'}>unmount sub-app</Link>
|
104
|
+
</div>
|
87
105
|
<Outlet />
|
88
106
|
</>
|
89
|
-
)
|
107
|
+
);
|
90
108
|
|
91
109
|
export default () => {
|
92
110
|
const { apps, MApp } = useModuleApps();
|
@@ -103,25 +121,25 @@ export default () => {
|
|
103
121
|
key={app.name}
|
104
122
|
path={`${app.name.toLowerCase()}/*`}
|
105
123
|
element={
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
124
|
+
<Component
|
125
|
+
loadable={{
|
126
|
+
loading: ({ pastDelay, error }: any) => {
|
127
|
+
if (error) {
|
128
|
+
return <div>error: {error?.message}</div>;
|
129
|
+
} else if (pastDelay) {
|
130
|
+
return <div>loading</div>;
|
131
|
+
} else {
|
132
|
+
return null;
|
133
|
+
}
|
134
|
+
},
|
135
|
+
}}
|
136
|
+
/>
|
119
137
|
}
|
120
138
|
/>
|
121
|
-
)
|
139
|
+
);
|
122
140
|
})}
|
123
|
-
</Route
|
124
|
-
)
|
141
|
+
</Route>,
|
142
|
+
),
|
125
143
|
);
|
126
144
|
|
127
145
|
return (
|
@@ -164,13 +182,10 @@ function App() {
|
|
164
182
|
|
165
183
|
After starting the application in this way, accessing the '/table' route will render the'Table 'sub-application, and accessing the'/dashboard 'route will render the'Dashboard' sub-application.
|
166
184
|
|
167
|
-
|
168
185
|
### Mix Mode
|
169
186
|
|
170
|
-
|
171
187
|
Of course, **sub-application components** and **centralized routing** can be mixed.
|
172
188
|
|
173
|
-
|
174
189
|
- One molecular application is activated as a **sub-application component**, and the other part is activated as a **centralized routing**.
|
175
190
|
- A molecular application can be activated either as a **centralized routing** or as a **sub-application component**.
|
176
191
|
|
@@ -178,7 +193,6 @@ Of course, **sub-application components** and **centralized routing** can be mix
|
|
178
193
|
|
179
194
|
By configuring the `loadable` configuration, loading components can be added for 「centralized routing」 and 「sub-applicati」, and errors, timeouts, flashes, etc. can be considered, so as to provide users with a better user experience. The design and implementation of this function refer to [react-loadable](https://github.com/jamiebuilds/react-loadable), and the basic functions are similar.
|
180
195
|
|
181
|
-
|
182
196
|
```tsx
|
183
197
|
function Loading() {
|
184
198
|
return <div>Loading...</div>;
|
@@ -2,6 +2,7 @@
|
|
2
2
|
sidebar_position: 5
|
3
3
|
title: Mixed Stack
|
4
4
|
---
|
5
|
+
|
5
6
|
# Mixed Stack
|
6
7
|
|
7
8
|
The Modern.js micro frontend scheme is based on the [Garfish](https://garfishjs.org/) package and provides some more out-of-the-box usage.
|
@@ -16,7 +17,6 @@ When your main application and sub-application are not all Modern.js application
|
|
16
17
|
**Modern.js** subapps compile to generate a standard [Garfish subapp export](https://www.garfishjs.org/guide/start#2%E5%AF%BC%E5%87%BA-provider-%E5%87%BD%E6%95%B0).
|
17
18
|
So you can directly access the standard micro frontend main application.
|
18
19
|
|
19
|
-
|
20
20
|
:::info
|
21
21
|
The child application is **Modern.js**, when the main application uses the native Garfish micro frontend, the **child application debugging mode** is not available.
|
22
22
|
:::
|
@@ -1,6 +1,7 @@
|
|
1
1
|
---
|
2
2
|
title: Add UI Components
|
3
3
|
---
|
4
|
+
|
4
5
|
# Add UI Components
|
5
6
|
|
6
7
|
In the previous chapter, we learned how to initialize a project and use configuration to modify the default behavior of Modern.js.
|
@@ -9,9 +10,9 @@ In this chapter, we continue to use the project code of the previous chapter and
|
|
9
10
|
|
10
11
|
In order to do better UI display and interaction, we introduce the component library [Antd](https://ant.design/index-cn) to develop, and use the `<List>` component instead of the primitive list. Add dependency first:
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
import { PackageManagerTabs } from '@theme';
|
14
|
+
|
15
|
+
<PackageManagerTabs command="add antd" />
|
15
16
|
|
16
17
|
Modify `src/routes/page.tsx` to import components at the top:
|
17
18
|
|
@@ -30,7 +30,6 @@ Options:
|
|
30
30
|
$ modern dev
|
31
31
|
|
32
32
|
info Starting dev server...
|
33
|
-
info App running at:
|
34
33
|
|
35
34
|
> Local: http://localhost:8080/
|
36
35
|
> Network: http://192.168.0.1:8080/
|
@@ -88,12 +87,14 @@ Options:
|
|
88
87
|
|
89
88
|
```
|
90
89
|
Bundle Analyzer saved report to /example/dist/report.html
|
91
|
-
File sizes after production build:
|
92
90
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
91
|
+
info Production file sizes:
|
92
|
+
|
93
|
+
File Size Gzipped
|
94
|
+
dist/static/js/lib-react.09721b5c.js 152.6 kB 49.0 kB
|
95
|
+
dist/html/main/index.html 5.8 kB 2.5 kB
|
96
|
+
dist/static/js/main.3568a38e.js 3.5 kB 1.4 kB
|
97
|
+
dist/static/css/main.03221f72.css 1.4 kB 741 B
|
97
98
|
```
|
98
99
|
|
99
100
|
手动在浏览器中打开上述 HTML 文件,可以看到打包产物的瓦片图,并进行包体积分析和优化:
|
@@ -123,7 +124,7 @@ Options:
|
|
123
124
|
|
124
125
|
### 添加入口
|
125
126
|
|
126
|
-
|
127
|
+
在 Modern.js 工程中,执行 `new` 命令添加入口的步骤如下:
|
127
128
|
|
128
129
|
```bash
|
129
130
|
$ npx modern new
|
@@ -134,7 +135,7 @@ $ npx modern new
|
|
134
135
|
|
135
136
|
### 启用可选功能
|
136
137
|
|
137
|
-
|
138
|
+
在 Modern.js 工程中,执行 `new` 命令启用可选能力的步骤如下:
|
138
139
|
|
139
140
|
```bash
|
140
141
|
$ npx modern new
|
@@ -156,7 +157,7 @@ pnpm 暂不支持使用 JSON 字符串作为参数值,可使用 `npm new` 开
|
|
156
157
|
|
157
158
|
## modern serve
|
158
159
|
|
159
|
-
`modern serve`
|
160
|
+
`modern serve` 命令用于在生产环境下启动 Modern.js 工程, 也可以用于在本地预览生产环境构建的产物。注意你需要提前执行 [`build`](/apis/app/commands#modern-build) 命令构建出对应产物。
|
160
161
|
|
161
162
|
```bash
|
162
163
|
Usage: modern serve [options]
|
@@ -2,6 +2,7 @@
|
|
2
2
|
title: '**/*.[tj]s'
|
3
3
|
sidebar_position: 1
|
4
4
|
---
|
5
|
+
|
5
6
|
# **/*.[tj]s
|
6
7
|
|
7
8
|
在 [BFF 函数写法](/guides/advanced-features/bff/type.html#函数写法)下,声明 API 路由的文件。除了[某些约定文件](/apis/app/hooks/api/api#白名单)外,`api` 目录下的文件会被注册为接口的路由。
|
@@ -66,7 +67,7 @@ export const get = async () => {
|
|
66
67
|
|
67
68
|
这样导出函数,则会得到一个 `GET` 接口。
|
68
69
|
|
69
|
-
|
70
|
+
Modern.js 工程中支持了 9 个 Method 定义,即:`GET`、`POST`、`PUT`、`DELETE`、`CONNECT`、`TRACE`、`PATCH`、`OPTION`、`HEAD`,即可以用这些 Method 作为函数导出的名字。
|
70
71
|
|
71
72
|
名字是大小不敏感的,就是说,如果是 `GET`,写成 `get`、`Get`、`GEt`、`GET`,都可以准确识别。而默认导出,即 `export default xxx` 则会被映射为 `Get`。
|
72
73
|
|
@@ -2,8 +2,9 @@
|
|
2
2
|
title: index.[tj]s
|
3
3
|
sidebar_position: 1
|
4
4
|
---
|
5
|
+
|
5
6
|
# index.[tj]s
|
6
7
|
|
7
|
-
扩展 Modern.js Web Server
|
8
|
+
扩展 Modern.js Web Server 的文件,在此文件中可以给 Modern.js 工程启动的 Web Server 添加 [Hook](/apis/app/runtime/web-server/hook) 或 [Middleware](/apis/app/runtime/web-server/middleware)。
|
8
9
|
|
9
10
|
可以对请求和响应进行拦截处理,鉴权与角色、请求预处理、异常兜底等。也可在内置处理逻辑(包括路由匹配、资源寻址、头部注入、页面渲染,静态 Web 托管)插入特定的业务逻辑。
|
@@ -10,7 +10,7 @@ Modern.js 7 ~ 8 月的最新版本为 v1.17.0,本双月的主要更新有:
|
|
10
10
|
|
11
11
|
- **支持 React 18**:完成框架和插件对 React 18 的适配。
|
12
12
|
- **包版本统一**:Modern.js 所有组成包的版本号进行统一,提供升级命令。
|
13
|
-
-
|
13
|
+
- **Modern.js Module 支持 bundle 构建**:Modern.js Module 项目,支持对产物做 bundle 构建。
|
14
14
|
- **Reduck v1.1**:发布 Reduck v1.1,使用文档全面更新。
|
15
15
|
|
16
16
|
## 支持 React 18
|
@@ -33,11 +33,11 @@ Modern.js 框架和相关插件完成对 React 18 的适配。现在,只需要
|
|
33
33
|
npx @modern-js/upgrade
|
34
34
|
```
|
35
35
|
|
36
|
-
##
|
36
|
+
## Modern.js Module 支持 bundle 构建
|
37
37
|
|
38
|
-
|
38
|
+
Modern.js Module 对底层实现进行重构,新增 [`output.buildConfig`](https://modernjs.dev/v1/docs/apis/module/config/output/build-config/) 配置,用于提供更加丰富的构建功能。
|
39
39
|
|
40
|
-
|
40
|
+
新的 Modern.js Module 项目,不仅支持对产物做 bundless 构建,也支持 bundle 构建。通过配置 `buildConfig` 下的 [`buildType`](https://modernjs.dev/v1/docs/apis/module/config/output/build-config/build-type) ,即可进行 bundle 构建:
|
41
41
|
|
42
42
|
```ts title="modern.config.ts"
|
43
43
|
import { defineConfig } from '@modern-js/module-tools';
|
@@ -80,7 +80,7 @@ Modern.js 7 ~ 8 月的最新版本为 v1.17.0,本双月的主要更新有:
|
|
80
80
|
|
81
81
|
- **支持 React 18**:完成框架和插件对 React 18 的适配。
|
82
82
|
- **包版本统一**:Modern.js 所有组成包的版本号进行统一,提供升级命令。
|
83
|
-
-
|
83
|
+
- **Modern.js Module 支持 bundle 构建**:Modern.js Module 项目,支持对产物做 bundle 构建。
|
84
84
|
- **Reduck v1.1**:发布 [Reduck v1.1](https://github.com/web-infra-dev/reduck),使用文档全面更新。
|
85
85
|
|
86
86
|
[了解更多 →](/community/blog/2022-0708-updates)
|
@@ -6,12 +6,10 @@ $ pnpm run dev
|
|
6
6
|
> modern dev
|
7
7
|
|
8
8
|
info Starting dev server...
|
9
|
-
|
9
|
+
ready Client compiled in 50ms
|
10
10
|
|
11
11
|
> Local: http://localhost:8080/
|
12
12
|
> Network: http://192.168.0.1:8080/
|
13
|
-
|
14
|
-
Client ✔ done in 76.10ms
|
15
13
|
```
|
16
14
|
|
17
15
|
在浏览器中打开 `http://localhost:8000/`,可以看到页面内容。
|
@@ -7,16 +7,9 @@
|
|
7
7
|
|
8
8
|
使用该选项前,你需要提前安装和注册 `@modern-js/plugin-proxy` 插件:
|
9
9
|
|
10
|
-
|
11
|
-
# npm
|
12
|
-
npm add @modern-js/plugin-proxy -D
|
13
|
-
|
14
|
-
# yarn
|
15
|
-
yarn add @modern-js/plugin-proxy -D
|
10
|
+
import { PackageManagerTabs } from '@theme';
|
16
11
|
|
17
|
-
|
18
|
-
pnpm add @modern-js/plugin-proxy -D
|
19
|
-
```
|
12
|
+
<PackageManagerTabs command="add @modern-js/plugin-proxy -D" />
|
20
13
|
|
21
14
|
安装完成后,在 `modern.config.ts` 文件中注册插件:
|
22
15
|
|
@@ -75,13 +68,11 @@ module.exports = {
|
|
75
68
|
执行 `dev`, 提示如下时,即代理服务器启动成功:
|
76
69
|
|
77
70
|
```bash
|
78
|
-
App running at:
|
79
|
-
|
80
71
|
Local: http://localhost:8080/
|
81
72
|
Network: http://192.168.0.1:8080/
|
82
73
|
|
83
|
-
|
84
|
-
|
74
|
+
info Starting proxy server.....
|
75
|
+
success Proxy server start on localhost:8899
|
85
76
|
```
|
86
77
|
|
87
78
|
访问 `localhost:8899`, 可以在 UI 界面上查看 Network 以及配置代理规则:
|
@@ -11,13 +11,11 @@ Modern.js 提供了开箱即用的全局代理插件 `@modern-js/plugin-proxy`
|
|
11
11
|
安装代理插件并配置代理规则后, 执行 `pnpm run dev` 命令:
|
12
12
|
|
13
13
|
```bash
|
14
|
-
App running at:
|
15
|
-
|
16
14
|
Local: http://localhost:8080/
|
17
15
|
Network: http://192.168.0.1:8080/
|
18
16
|
|
19
|
-
|
20
|
-
|
17
|
+
info Starting proxy server.....
|
18
|
+
success Proxy server start on localhost:8899
|
21
19
|
```
|
22
20
|
|
23
21
|
在控制台中可以看到代理服务器成功启动。
|
@@ -0,0 +1 @@
|
|
1
|
+
Modern.js 支持 [Express.js](https://expressjs.com/) 和 [Koa.js](https://koajs.com/) 作为可选的 BFF 运行时框架,请参考[「BFF - 运行时框架」](/guides/advanced-features/bff/frameworks.html)。
|
@@ -18,7 +18,7 @@ Modern.js Builder 是 Modern.js 底层的构建工具,请阅读 [构建能力]
|
|
18
18
|
该选项**用于配置 Modern.js Builder 构建插件**,如果你需要配置其他类型的插件,请选择对应的配置方式:
|
19
19
|
|
20
20
|
- 配置 Modern.js 框架插件,请使用 [plugins](/configure/app/plugins) 配置项。
|
21
|
-
- 配置
|
21
|
+
- 配置 Rspack 或 webpack 插件,请使用 [tools.bundlerChain](/configure/app/tools/bundler-chain) 配置项。
|
22
22
|
- 配置 Babel 插件,请使用 [tools.babel](/configure/app/tools/babel) 配置项。
|
23
23
|
|
24
24
|
## 何时使用
|
@@ -16,8 +16,7 @@ sidebar_position: 9
|
|
16
16
|
该选项**用于配置框架插件**,如果你需要配置其他类型的插件,请选择对应的配置方式:
|
17
17
|
|
18
18
|
- 配置 Modern.js Builder 插件,请使用 [builderPlugins](/configure/app/builder-plugins) 配置项。
|
19
|
-
- 配置
|
20
|
-
- 配置 Rspack 插件,请使用 [tools.rspack](/configure/app/tools/rspack) 或 [tools.bundlerChain](/configure/app/tools/bundler-chain) 配置项。
|
19
|
+
- 配置 Rspack 或 webpack 插件,请使用 [tools.bundlerChain](/configure/app/tools/bundler-chain) 配置项。
|
21
20
|
- 配置 Babel 插件,请使用 [tools.babel](/configure/app/tools/babel) 配置项。
|
22
21
|
|
23
22
|
## 插件类型
|
@@ -49,6 +49,6 @@ import('./bootstrap.jsx');
|
|
49
49
|
此时,就可以在当前页面中消费任意的远程模块了。
|
50
50
|
|
51
51
|
:::info
|
52
|
-
Modern.js 未对
|
52
|
+
Modern.js 未对 ModuleFederationPlugin 进行封装,请通过 [tools.bundlerChain](/configure/app/tools/bundler-chain) 自行配置 ModuleFederationPlugin。
|
53
53
|
|
54
54
|
:::
|
@@ -1,67 +1,28 @@
|
|
1
1
|
---
|
2
|
-
sidebar_position:
|
2
|
+
sidebar_position: 4
|
3
3
|
---
|
4
4
|
|
5
5
|
# 路径别名
|
6
6
|
|
7
|
-
|
7
|
+
import Alias from '@modern-js/builder-doc/docs/zh/shared/alias';
|
8
8
|
|
9
|
-
|
10
|
-
{
|
11
|
-
'@': '<appDirectory>/src',
|
12
|
-
'@shared': '<appDirectory>/shared',
|
13
|
-
}
|
14
|
-
```
|
15
|
-
|
16
|
-
:::info
|
17
|
-
在开启可选功能时,new 命令也会动态的添加内置别名,例如启用 BFF 时默认会添加 `@api` 别名。
|
9
|
+
<Alias />
|
18
10
|
|
19
|
-
|
11
|
+
## 默认别名
|
20
12
|
|
21
|
-
|
22
|
-
|
23
|
-
```bash
|
24
|
-
.
|
25
|
-
├── common
|
26
|
-
│ ├── styles
|
27
|
-
│ │ └── base.css
|
28
|
-
│ └── utils
|
29
|
-
│ └── index.ts
|
30
|
-
└── App.tsx
|
31
|
-
```
|
32
|
-
|
33
|
-
`src/App.tsx` 中写法如下:
|
34
|
-
|
35
|
-
```ts
|
36
|
-
import utils from '@/src/common/utils';
|
37
|
-
import '@/src/common/styles/base.css';
|
38
|
-
```
|
39
|
-
|
40
|
-
Modern.js 也提供了自定义别名的方式,以添加 `@common` 别名为例:
|
41
|
-
|
42
|
-
对于 TypeScript 项目,只需要在项目根目录 `tsconfig.json` 下配置 `compilerOptions.paths`:
|
13
|
+
Modern.js 框架内置了以下别名:
|
43
14
|
|
44
15
|
```json
|
45
16
|
{
|
46
|
-
"
|
47
|
-
|
48
|
-
"@/*": ["./src/*"],
|
49
|
-
"@/common/*": ["./src/common/*"]
|
50
|
-
}
|
51
|
-
}
|
17
|
+
"@": "./src",
|
18
|
+
"@shared": "./shared"
|
52
19
|
}
|
53
20
|
```
|
54
21
|
|
55
|
-
|
22
|
+
此外,在启用框架的 BFF 插件时,默认会添加 `@api` 别名。
|
56
23
|
|
57
|
-
```
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
'@common': './src/common',
|
62
|
-
},
|
63
|
-
},
|
64
|
-
});
|
24
|
+
```json
|
25
|
+
{
|
26
|
+
"@api": "./api"
|
27
|
+
}
|
65
28
|
```
|
66
|
-
|
67
|
-
对于别名配置的具体用法,请参考 [source.alias 文档](/configure/app/source/alias)。
|
@@ -1,5 +1,5 @@
|
|
1
1
|
---
|
2
|
-
sidebar_position:
|
2
|
+
sidebar_position: 1
|
3
3
|
---
|
4
4
|
|
5
5
|
# 样式开发
|
@@ -61,16 +61,31 @@ Modern.js 内部集成了 Babel 的 [babel-plugin-styled-components](https://git
|
|
61
61
|
|
62
62
|
## 使用 Tailwind CSS
|
63
63
|
|
64
|
-
[Tailwind CSS](https://tailwindcss.com/) 是一个以 Utility Class 为基础的 CSS
|
64
|
+
[Tailwind CSS](https://tailwindcss.com/) 是一个以 Utility Class 为基础的 CSS 框架和设计系统,可以快速地为组件添加常用样式,同时支持主题样式的灵活扩展。
|
65
65
|
|
66
|
-
|
66
|
+
在 Modern.js 中使用 [Tailwind CSS](https://tailwindcss.com/),你只需要按照以下步骤操作:
|
67
|
+
|
68
|
+
1. 在项目根目录下执行 `pnpm run new`,按照如下进行选择:
|
67
69
|
|
68
70
|
```text
|
69
71
|
? 请选择你想要的操作 启用可选功能
|
70
72
|
? 请选择功能名称 启用 「Tailwind CSS」 支持
|
71
73
|
```
|
72
74
|
|
73
|
-
|
75
|
+
成功开启后,会看到 `package.json` 中新增了依赖:
|
76
|
+
|
77
|
+
```json title="./package.json"
|
78
|
+
{
|
79
|
+
"dependencies": {
|
80
|
+
"tailwindcss": "^3.0.0"
|
81
|
+
},
|
82
|
+
"devDependencies": {
|
83
|
+
"@modern-js/plugin-tailwindcss": "^2.0.0"
|
84
|
+
}
|
85
|
+
}
|
86
|
+
```
|
87
|
+
|
88
|
+
2. 在 `modern.config.ts` 中注册 Tailwind 插件:
|
74
89
|
|
75
90
|
```ts title="modern.config.ts"
|
76
91
|
import { tailwindcssPlugin } from '@modern-js/plugin-tailwindcss';
|
@@ -80,29 +95,34 @@ export default defineConfig({
|
|
80
95
|
});
|
81
96
|
```
|
82
97
|
|
83
|
-
|
98
|
+
3. 创建 `index.css` 文件,添加以下代码:
|
99
|
+
|
100
|
+
```css title="index.css"
|
101
|
+
@tailwind base;
|
102
|
+
@tailwind components;
|
103
|
+
@tailwind utilities;
|
104
|
+
```
|
105
|
+
|
106
|
+
:::info
|
107
|
+
根据需求不同,你可以选择性地导入 Tailwind CSS 提供的 CSS 样式。请参考 [`@tailwind` 文档](https://tailwindcss.com/docs/functions-and-directives#tailwind) 来了解 `@tailwind` 指令的详细用法。
|
108
|
+
:::
|
109
|
+
|
110
|
+
4. 引用 `index.css` 文件,比如在入口的根组件 `src/App.jsx` 添加如下代码:
|
84
111
|
|
85
112
|
```js
|
86
|
-
import '
|
87
|
-
import 'tailwindcss/components.css';
|
88
|
-
import 'tailwindcss/utilities.css';
|
113
|
+
import './index.css';
|
89
114
|
```
|
90
115
|
|
91
|
-
然后即可在各个组件中使用 Tailwind CSS 提供的 Utility Class 了:
|
116
|
+
5. 然后即可在各个组件中使用 Tailwind CSS 提供的 Utility Class 了:
|
92
117
|
|
93
118
|
```tsx
|
94
|
-
const
|
119
|
+
const Hello = () => (
|
95
120
|
<div className="h-12 w-48">
|
96
121
|
<p className="text-xl font-medium text-black">hello world</p>
|
97
122
|
</div>
|
98
123
|
);
|
99
124
|
```
|
100
125
|
|
101
|
-
:::info 补充信息
|
102
|
-
根据需求不同,你可以选择性的导入 Tailwind CSS 提供的 CSS 文件。由于使用 `@tailwind` 与直接导入 CSS 文件的作用等价,因此关于 Tailwind CSS 提供的 CSS 文件的用途,可以参考 [`@tailwind` 的使用](https://tailwindcss.com/docs/functions-and-directives#tailwind) 文档中注释里的内容。
|
103
|
-
|
104
|
-
:::
|
105
|
-
|
106
126
|
### 配置 Tailwind CSS
|
107
127
|
|
108
128
|
在 Modern.js 中,你有两种方式来配置 Tailwind CSS:
|