@modern-js/main-doc 2.35.0 → 2.35.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. package/docs/en/apis/app/commands.mdx +12 -11
  2. package/docs/en/components/debug-app.mdx +1 -3
  3. package/docs/en/components/global-proxy-config.mdx +4 -13
  4. package/docs/en/components/global-proxy.mdx +2 -4
  5. package/docs/en/components/init-app.mdx +1 -1
  6. package/docs/en/configure/app/builder-plugins.mdx +2 -2
  7. package/docs/en/configure/app/plugins.mdx +3 -4
  8. package/docs/en/configure/app/server/base-url.mdx +0 -2
  9. package/docs/en/configure/app/source/enable-async-entry.mdx +1 -1
  10. package/docs/en/guides/basic-features/alias.mdx +1 -1
  11. package/docs/en/guides/basic-features/css.mdx +35 -15
  12. package/docs/en/guides/basic-features/data-fetch.mdx +12 -12
  13. package/docs/en/guides/basic-features/html.mdx +2 -2
  14. package/docs/en/guides/basic-features/routes.mdx +27 -15
  15. package/docs/en/guides/get-started/quick-start.mdx +8 -17
  16. package/docs/en/guides/get-started/upgrade.mdx +10 -4
  17. package/docs/en/guides/topic-detail/framework-plugin/implement.mdx +2 -0
  18. package/docs/en/guides/topic-detail/micro-frontend/c01-introduction.mdx +1 -0
  19. package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +24 -17
  20. package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +51 -37
  21. package/docs/en/guides/topic-detail/micro-frontend/c04-communicate.mdx +1 -0
  22. package/docs/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +1 -1
  23. package/docs/en/tutorials/first-app/c02-component.mdx +4 -3
  24. package/docs/zh/apis/app/commands.mdx +10 -9
  25. package/docs/zh/apis/app/hooks/api/api.mdx +2 -1
  26. package/docs/zh/apis/app/hooks/server/index_.mdx +2 -1
  27. package/docs/zh/components/debug-app.mdx +1 -3
  28. package/docs/zh/components/global-proxy-config.mdx +4 -13
  29. package/docs/zh/components/global-proxy.mdx +2 -4
  30. package/docs/zh/configure/app/builder-plugins.mdx +1 -1
  31. package/docs/zh/configure/app/plugins.mdx +1 -2
  32. package/docs/zh/configure/app/server/base-url.mdx +0 -2
  33. package/docs/zh/configure/app/source/enable-async-entry.mdx +1 -1
  34. package/docs/zh/guides/basic-features/alias.mdx +1 -1
  35. package/docs/zh/guides/basic-features/css.mdx +35 -15
  36. package/docs/zh/guides/basic-features/data-fetch.mdx +11 -12
  37. package/docs/zh/guides/basic-features/html.mdx +4 -5
  38. package/docs/zh/guides/basic-features/routes.mdx +26 -19
  39. package/docs/zh/guides/get-started/quick-start.mdx +8 -17
  40. package/docs/zh/guides/get-started/upgrade.mdx +10 -4
  41. package/docs/zh/guides/topic-detail/framework-plugin/hook-list.mdx +1 -1
  42. package/docs/zh/guides/topic-detail/framework-plugin/implement.mdx +2 -0
  43. package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +45 -21
  44. package/docs/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +51 -33
  45. package/docs/zh/guides/topic-detail/micro-frontend/c04-communicate.mdx +1 -0
  46. package/docs/zh/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +1 -0
  47. package/docs/zh/tutorials/first-app/c02-component.mdx +4 -3
  48. package/package.json +7 -7
@@ -13,6 +13,7 @@ Through this chapter you can learn:
13
13
  ## Create an app
14
14
 
15
15
  Currently supports two routing modes
16
+
16
17
  - Self-controlled routing
17
18
  - Conventional routing
18
19
 
@@ -20,7 +21,6 @@ First, clarify the routing mode of the main application [create a file-based rou
20
21
 
21
22
  In this experience we will create two sub-applications Table and Dashboard for the main application (Table is reduced routing, Dashboard is self-controlled routing)
22
23
 
23
-
24
24
  ### File-based Routing Main App
25
25
 
26
26
  Initialize the project with a command line:
@@ -39,11 +39,12 @@ After the project is created, we can enable the `micro frontend` through `pnpm r
39
39
 
40
40
  Next, let's register the micro frontend plugin and add the main micro frontend app and add the list of sub-apps:
41
41
 
42
- import EnableMicroFrontend from "@site-docs-en/components/enable-micro-frontend";
42
+ import EnableMicroFrontend from '@site-docs-en/components/enable-micro-frontend';
43
43
 
44
44
  <EnableMicroFrontend />
45
45
 
46
46
  Then we create two new directories in the routes folder
47
+
47
48
  - table (for loading conventional routing sub-applications)
48
49
  - dashboard (for loading self-controlled routing sub-applications)
49
50
 
@@ -61,8 +62,8 @@ const Index = () => {
61
62
  <div>
62
63
  <Table />
63
64
  </div>
64
- )
65
- }
65
+ );
66
+ };
66
67
 
67
68
  export default Index;
68
69
  ```
@@ -79,11 +80,12 @@ const Index = () => {
79
80
  <div>
80
81
  <Dashboard />
81
82
  </div>
82
- )
83
- }
83
+ );
84
+ };
84
85
 
85
86
  export default Index;
86
87
  ```
88
+
87
89
  #### route link
88
90
 
89
91
  At this time, the main application configuration has been completed, and the sub-application can be loaded through the route, and the `layout.tsx` of the main application can be modified to jump to the route:
@@ -93,9 +95,15 @@ import { Outlet, Link } from '@modern-js/runtime/router';
93
95
 
94
96
  const Layout = () => (
95
97
  <div>
96
- <div><Link to={'/table'}>Load file-base routing sub-app</Link></div>
97
- <div><Link to={'/dashboard'}>Load self-controlled routing sub-app</Link></div>
98
- <div><Link to={'/'}>unmount sub-app</Link></div>
98
+ <div>
99
+ <Link to={'/table'}>Load file-base routing sub-app</Link>
100
+ </div>
101
+ <div>
102
+ <Link to={'/dashboard'}>Load self-controlled routing sub-app</Link>
103
+ </div>
104
+ <div>
105
+ <Link to={'/'}>unmount sub-app</Link>
106
+ </div>
99
107
  <Outlet />
100
108
  </div>
101
109
  );
@@ -127,7 +135,7 @@ Since it is a self-controlled route, we delete the `routes/` folder and add the
127
135
 
128
136
  #### Load sub-app
129
137
 
130
- import CustomRouterMicroFrontend from "@site-docs-en/components/custom-router-micro-frontend";
138
+ import CustomRouterMicroFrontend from '@site-docs-en/components/custom-router-micro-frontend';
131
139
 
132
140
  <CustomRouterMicroFrontend />
133
141
 
@@ -155,7 +163,7 @@ import { garfishPlugin } from '@modern-js/plugin-garfish';
155
163
 
156
164
  export default defineConfig({
157
165
  dev: {
158
- port: 8081
166
+ port: 8081,
159
167
  },
160
168
  runtime: {
161
169
  router: true,
@@ -172,10 +180,8 @@ add `src/routes/page.tsx`:
172
180
 
173
181
  ```js title="src/routes/page.tsx"
174
182
  const Index = () => {
175
- return (
176
- <div className="container-box">subApp</div>
177
- )
178
- }
183
+ return <div className="container-box">subApp</div>;
184
+ };
179
185
 
180
186
  export default Index;
181
187
  ```
@@ -204,7 +210,7 @@ import { garfishPlugin } from '@modern-js/plugin-garfish';
204
210
 
205
211
  export default defineConfig({
206
212
  dev: {
207
- port: 8082
213
+ port: 8082,
208
214
  },
209
215
  runtime: {
210
216
  router: true,
@@ -224,7 +230,7 @@ And add code in `src/App.tsx`, note that you need to parse from `props` and pass
224
230
  ```js title="src/App.tsx"
225
231
  import { BrowserRouter, Route, Routes } from '@modern-js/runtime/router';
226
232
 
227
- export default (props: {basename: string}) => {
233
+ export default (props: { basename: string }) => {
228
234
  const { basename } = props;
229
235
 
230
236
  return (
@@ -241,6 +247,7 @@ export default (props: {basename: string}) => {
241
247
  ## Debug
242
248
 
243
249
  Start the application by executing the `pnpm run dev` command in the directory in sequence:
250
+
244
251
  - masterApp `http://localhost:8080`
245
252
  - table subapplication (conventional routing) `http://localhost:8081`
246
253
  - dashboard subapplication (self-controlled routing) `http://localhost:8082`
@@ -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 application 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
+ 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 "@site-docs-en/components/enable-micro-frontend";
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 "@site-docs-en/components/micro-runtime-config";
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
- name: 'Table',
45
- entry: 'http://localhost:8001',
46
- // activeWhen: '/table'
47
- }, {
48
- name: 'Dashboard',
49
- entry: 'http://localhost:8002'
50
- // activeWhen: '/dashboard'
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 { RouterProvider, Route, createBrowserRouter, createRoutesFromElements, BrowserRouter, Link, Outlet } from '@modern-js/runtime/router';
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><Link to={'/table'}>load file-based sub-app</Link></div>
85
- <div><Link to={'/dashboard'}>load self-controlled sub-app</Link></div>
86
- <div><Link to={'/'}>unmount sub-app</Link></div>
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
- <Component
107
- loadable={{
108
- loading: ({ pastDelay, error }: any) => {
109
- if (error) {
110
- return <div>error: {error?.message}</div>;
111
- } else if (pastDelay) {
112
- return <div>loading</div>;
113
- } else {
114
- return null;
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: 4
3
3
  title: Communicate
4
4
  ---
5
+
5
6
  # Communicate
6
7
 
7
8
  ## Props
@@ -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
- ```bash
13
- pnpm add antd
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
- 122.35 KB dist/static/js/885.1d4fbe5a.js
94
- 2.3 KB dist/static/js/main.4b8e8d64.js
95
- 761 B dist/static/js/runtime-main.edb7cf35.js
96
- 645 B dist/static/css/main.0dd3ecc1.css
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
- 在应用工程中,执行 `new` 命令添加入口如下:
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
- 在应用工程中,执行 `new` 命令启用可选能力如下:
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` 命令用于在生产环境下启用应用工程, 注意需要提前执行 [`build`](/apis/app/commands#modern-build) 命令构建出对应产物。
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
- 应用工程中支持了 9 个 Method 定义,即:`GET`、`POST`、`PUT`、`DELETE`、`CONNECT`、`TRACE`、`PATCH`、`OPTION`、`HEAD`,即可以用这些 Method 作为函数导出的名字。
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 的文件,在此文件中可以给应用工程启动的 Web Server 添加 [Hook](/apis/app/runtime/web-server/hook) 或 [Middleware](/apis/app/runtime/web-server/middleware)。
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 托管)插入特定的业务逻辑。
@@ -6,12 +6,10 @@ $ pnpm run dev
6
6
  > modern dev
7
7
 
8
8
  info Starting dev server...
9
- info App running at:
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
- ```bash
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
- # pnpm
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
- info Starting the proxy server.....
84
- success Proxy Server start on localhost:8899
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
- info Starting the proxy server.....
20
- success Proxy Server start on localhost:8899
17
+ info Starting proxy server.....
18
+ success Proxy server start on localhost:8899
21
19
  ```
22
20
 
23
21
  在控制台中可以看到代理服务器成功启动。
@@ -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
- - 配置 webpack 插件,请使用 [tools.webpack](/configure/app/tools/webpack) [tools.webpackChain](/configure/app/tools/webpack-chain) 配置项。
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
- - 配置 webpack 插件,请使用 [tools.webpack](/configure/app/tools/webpack)、[tools.webpackChain](/configure/app/tools/webpack-chain) [tools.bundlerChain](/configure/app/tools/bundler-chain) 配置项。
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
  ## 插件类型
@@ -25,8 +25,6 @@ export default defineConfig({
25
25
  `dev` 之后可以看到路由访问会加上对应前缀:
26
26
 
27
27
  ```bash
28
- App running at:
29
-
30
28
  > Local: http://localhost:8080/base/
31
29
  > Network: http://192.168.0.1:8080/base/
32
30
  ```
@@ -49,6 +49,6 @@ import('./bootstrap.jsx');
49
49
  此时,就可以在当前页面中消费任意的远程模块了。
50
50
 
51
51
  :::info
52
- Modern.js 未对 webpack 的 ModuleFederationPlugin 进行封装,请通过 [tools.webpackChain](/configure/app/tools/webpack-chain) 自行配置 ModuleFederationPlugin。
52
+ Modern.js 未对 ModuleFederationPlugin 进行封装,请通过 [tools.bundlerChain](/configure/app/tools/bundler-chain) 自行配置 ModuleFederationPlugin。
53
53
 
54
54
  :::
@@ -1,5 +1,5 @@
1
1
  ---
2
- sidebar_position: 3
2
+ sidebar_position: 4
3
3
  ---
4
4
 
5
5
  # 路径别名
@@ -1,5 +1,5 @@
1
1
  ---
2
- sidebar_position: 2
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 框架和设计系统,可以快速地为组件添加常用样式,同时支持主题样式的灵活扩展。在 Modern.js 中使用 [Tailwind CSS](https://tailwindcss.com/),只需要在项目根目录下执行 `pnpm run new` 并开启。
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
- `modern.config.ts` 中注册 Tailwind 插件:
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
- 使用时在入口的根组件(如 `src/App.jsx`)添加如下代码:
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 'tailwindcss/base.css';
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 App = () => (
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: