@modern-js/main-doc 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/en/apis/app/commands.mdx +297 -0
  3. package/en/apis/app/hooks/_category_.json +1 -1
  4. package/en/apis/app/hooks/src/routes.mdx +2 -2
  5. package/en/components/init-app.mdx +5 -5
  6. package/en/configure/app/bff/prefix.mdx +2 -3
  7. package/en/configure/app/bff/proxy.mdx +1 -1
  8. package/en/configure/app/dev/before-start-url.mdx +13 -0
  9. package/en/configure/app/dev/host.mdx +13 -0
  10. package/en/configure/app/output/ssg.mdx +3 -3
  11. package/en/configure/app/runtime/master-app.mdx +1 -1
  12. package/en/configure/app/source/entries-dir.mdx +1 -1
  13. package/en/configure/app/testing/transformer.mdx +1 -1
  14. package/en/configure/app/tools/jest.mdx +1 -1
  15. package/en/guides/advanced-features/rspack-start.mdx +69 -0
  16. package/en/guides/advanced-features/ssg.mdx +8 -8
  17. package/en/guides/basic-features/alias.mdx +4 -4
  18. package/en/guides/basic-features/data-fetch.mdx +4 -4
  19. package/en/guides/basic-features/routes.mdx +23 -7
  20. package/en/guides/concept/builder.mdx +1 -1
  21. package/en/guides/get-started/quick-start.mdx +2 -2
  22. package/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +1 -1
  23. package/en/tutorials/first-app/c07-container.mdx +17 -17
  24. package/en/tutorials/first-app/c08-entries.mdx +23 -23
  25. package/package.json +3 -3
  26. package/scripts/summary.en.json +1 -1
  27. package/scripts/summary.zh.json +1 -1
  28. package/zh/apis/app/commands.mdx +299 -0
  29. package/zh/apis/app/hooks/_category_.json +1 -1
  30. package/zh/apis/app/hooks/src/routes.mdx +2 -2
  31. package/zh/components/init-app.mdx +5 -5
  32. package/zh/configure/app/bff/prefix.mdx +1 -1
  33. package/zh/configure/app/bff/proxy.mdx +1 -1
  34. package/zh/configure/app/dev/before-start-url.mdx +13 -0
  35. package/zh/configure/app/dev/host.mdx +13 -0
  36. package/zh/configure/app/output/ssg.mdx +3 -3
  37. package/zh/configure/app/source/entries-dir.mdx +1 -1
  38. package/zh/guides/advanced-features/rspack-start.mdx +69 -0
  39. package/zh/guides/advanced-features/ssg.mdx +8 -8
  40. package/zh/guides/advanced-features/ssr.mdx +3 -2
  41. package/zh/guides/basic-features/alias.mdx +4 -4
  42. package/zh/guides/basic-features/data-fetch.mdx +4 -4
  43. package/zh/guides/basic-features/routes.mdx +23 -7
  44. package/zh/guides/concept/builder.mdx +2 -2
  45. package/zh/guides/get-started/quick-start.mdx +2 -2
  46. package/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +1 -1
  47. package/zh/tutorials/first-app/c07-container.mdx +17 -17
  48. package/zh/tutorials/first-app/c08-entries.mdx +23 -23
  49. package/en/apis/app/commands/_category_.json +0 -5
  50. package/en/apis/app/commands/build.mdx +0 -39
  51. package/en/apis/app/commands/dev.mdx +0 -61
  52. package/en/apis/app/commands/inspect.mdx +0 -61
  53. package/en/apis/app/commands/lint.mdx +0 -19
  54. package/en/apis/app/commands/new.mdx +0 -55
  55. package/en/apis/app/commands/serve.mdx +0 -27
  56. package/en/apis/app/commands/test.mdx +0 -35
  57. package/en/apis/app/commands/upgrade.mdx +0 -18
  58. package/zh/apis/app/commands/_category_.json +0 -5
  59. package/zh/apis/app/commands/build.mdx +0 -39
  60. package/zh/apis/app/commands/dev.mdx +0 -61
  61. package/zh/apis/app/commands/inspect.mdx +0 -61
  62. package/zh/apis/app/commands/lint.mdx +0 -19
  63. package/zh/apis/app/commands/new.mdx +0 -54
  64. package/zh/apis/app/commands/serve.mdx +0 -27
  65. package/zh/apis/app/commands/test.mdx +0 -35
  66. package/zh/apis/app/commands/upgrade.mdx +0 -18
@@ -0,0 +1,69 @@
1
+ ---
2
+ title: 使用 Rspack
3
+ sidebar_position: 12
4
+ ---
5
+
6
+ # 使用 Rspack
7
+
8
+ [Rspack](https://www.rspack.org/) 是字节跳动 Web Infra 团队自研的 Rust Bundler,核心架构对齐 webpack 实现,并对社区常用的构建能力做了开箱即用的支持。
9
+
10
+ Rspack 通过以下方式来提升编译性能:
11
+
12
+ - 高度 LTO 优化的 Native code。
13
+ - 充分利用多核优势,整个编译过程充分进行多线程优化。
14
+ - 基于请求的按需编译(Lazy Compilation),减小每次编译的模块数目,以提升冷启动的速度。
15
+
16
+ ## 初始化 rspack 项目
17
+
18
+ Modern.js 生成器会提供一个可交互的问答界面,只需将构建工具选择为**rspack**,即可创建一个 rspack 项目:
19
+
20
+ ```bash
21
+ $ npx @modern-js/create myapp
22
+ ? 请选择你想创建的工程类型 应用
23
+ ? 请选择开发语言 TS
24
+ ? 请选择包管理工具 pnpm
25
+ ? 请选择构建工具 rspack
26
+ ```
27
+
28
+ 项目创建完成后,在项目中执行 `pnpm run dev` 即可体验项目。更多项目信息可参考[快速上手](/guides/get-started/quick-start.html)。
29
+
30
+ :::tip
31
+ 使用 rspack 作为打包工具时,以下功能暂不支持使用:
32
+
33
+ - 服务端渲染(SSR)
34
+ - 静态站点生成(SSG)
35
+ - 微前端(Micro Frontend)
36
+ - Storybook 调试
37
+
38
+ :::
39
+
40
+ ## 从 webpack 迁移至 rspack
41
+
42
+ 通过执行 `pnpm run new` 可启用 rspack 构建:
43
+
44
+ ```bash
45
+ $ pnpm run new
46
+ ? 请选择你想要的操作 启用可选功能
47
+ ? 启用可选功能 启用「rspack 构建」
48
+ ```
49
+
50
+ 执行命令后,在 modern.config.ts 中开启 rspack 构建:
51
+
52
+ ```ts title=modern.config.ts
53
+ import appTools, { defineConfig } from '@modern-js/app-tools';
54
+
55
+ export default defineConfig<'rspack'>({
56
+ runtime: {
57
+ router: true,
58
+ },
59
+ plugins: [
60
+ appTools({
61
+ bundler: 'experimental-rspack',
62
+ }),
63
+ ],
64
+ });
65
+ ```
66
+
67
+ :::tip
68
+ 从 webpack 迁移至 rspack,会有一些构建和配置能力上的差异,详情可参考:[配置差异](https://modernjs.dev/builder/guide/advanced/rspack-start.html#从-webpack-迁移到-rspack)
69
+ :::
@@ -37,14 +37,14 @@ SSG 在**约定式路由**和**自控式路由**下的使用方式不同。
37
37
  ```
38
38
  .
39
39
  ├── src
40
-    └── routes
41
-    ├── layout.tsx
42
-    ├── page.tsx
43
-    └── user
44
-    ├── layout.tsx
45
-    ├── page.tsx
46
-    └── profile
47
-    └── page.tsx
40
+ └── routes
41
+ ├── layout.tsx
42
+ ├── page.tsx
43
+ └── user
44
+ ├── layout.tsx
45
+ ├── page.tsx
46
+ └── profile
47
+ └── page.tsx
48
48
  ```
49
49
 
50
50
  上述文件目录将会生成以下三条路由:
@@ -20,8 +20,8 @@ sidebar_position: 3
20
20
 
21
21
  Modern.js 中提供了 Data Loader,方便开发者在 SSR、CSR 下同构的获取数据。每个路由模块,如 `layout.tsx` 和 `page.tsx` 都可以定义自己的 Data Loader:
22
22
 
23
- ```ts title="src/routes/page.tsx"
24
- export const loader = () => {
23
+ ```ts title="src/routes/page.loader.ts"
24
+ export default () => {
25
25
  return {
26
26
  message: 'Hello World',
27
27
  };
@@ -31,6 +31,7 @@ export const loader = () => {
31
31
  在组件中可以通过 Hooks API 的方式获取 `loader` 函数返回的数据:
32
32
 
33
33
  ```tsx
34
+ import { useLoaderData } from '@modern-js/runtime/router'
34
35
  export default () => {
35
36
  const data = useLoaderData();
36
37
  return <div>{data.message}</div>;
@@ -23,10 +23,10 @@ Modern.js 允许在 JS 和 CSS 中使用别名导入自定义目录下的模块
23
23
  ```bash
24
24
  .
25
25
  ├── common
26
-    ├── styles
27
-       └── base.css
28
-    └── utils
29
-    └── index.ts
26
+ ├── styles
27
+ └── base.css
28
+ └── utils
29
+ └── index.ts
30
30
  ├── App.tsx
31
31
  ```
32
32
 
@@ -82,9 +82,9 @@ export default async (): Promise<ProfileData> => {
82
82
 
83
83
  ```tsx
84
84
  // routes/user/[id]/page.loader.ts
85
- import { LoaderArgs } from '@modern-js/runtime/router';
85
+ import { LoaderFunctionArgs } from '@modern-js/runtime/router';
86
86
 
87
- export default async ({ params }: LoaderArgs) => {
87
+ export default async ({ params }: LoaderFunctionArgs) => {
88
88
  const { id } = params;
89
89
  const res = await fetch(`https://api/user/${id}`);
90
90
  return res.json();
@@ -101,9 +101,9 @@ export default async ({ params }: LoaderArgs) => {
101
101
 
102
102
  ```tsx
103
103
  // routes/user/[id]/page.loader.ts
104
- import { LoaderArgs } from '@modern-js/runtime/router';
104
+ import { LoaderFunctionArgs } from '@modern-js/runtime/router';
105
105
 
106
- export default async ({ request }: LoaderArgs) => {
106
+ export default async ({ request }: LoaderFunctionArgs) => {
107
107
  const url = new URL(request.url);
108
108
  const userId = url.searchParams.get('id');
109
109
  return queryUser(userId);
@@ -109,7 +109,7 @@ export default () => {
109
109
  .
110
110
  └── routes
111
111
  ├── blog
112
-    └── page.tsx
112
+ └── page.tsx
113
113
  ├── layout.tsx
114
114
  ├── page.tsx
115
115
  └── user
@@ -156,9 +156,9 @@ export default () => {
156
156
  ```
157
157
  └── routes
158
158
  ├── [id]
159
-    └── page.tsx
159
+ └── page.tsx
160
160
  ├── blog
161
-    └── page.tsx
161
+ └── page.tsx
162
162
  └── page.tsx
163
163
  ```
164
164
 
@@ -181,7 +181,7 @@ export default () => {
181
181
  └── routes
182
182
  ├── $.tsx
183
183
  ├── blog
184
-    └── page.tsx
184
+ └── page.tsx
185
185
  └── page.tsx
186
186
  ```
187
187
 
@@ -248,9 +248,9 @@ Modern.js 会生成 `/login` 和 `/sign` 两条路由,`__auth/layout.tsx` 组
248
248
  .
249
249
  └── routes
250
250
  ├── blog
251
-    ├── [id]
252
-       └── page.tsx
253
-    └── page.tsx
251
+ ├── [id]
252
+ └── page.tsx
253
+ └── page.tsx
254
254
  ├── layout.tsx
255
255
  ├── loading.tsx
256
256
  └── page.tsx
@@ -292,6 +292,22 @@ Modern.js 建议必须有根 layout 和根 loading。
292
292
 
293
293
  同理,当路由从 `/` 或者 `/blog` 跳转到 `/blog/123` 时,如果 `blog/[id]/page` 组件的 JS Chunk 还未加载,也会先展示 `loading.tsx` 中导出的组件 UI。
294
294
 
295
+ ### 路由重定向
296
+
297
+ 可以通过创建 [`data loader`](/guides/basic-features/data-fetch) 文件做路由的重定向,如有文件 `routes/user/page.tsx`,想对这个文件对应的路由做重定向,可以创建 `routes/user/page.loader.ts` 文件:
298
+
299
+ ```ts title="routes/user/page.loader.ts"
300
+ import { redirect } from "@edenx/runtime/router"
301
+
302
+ export default () => {
303
+ const user = await getUser();
304
+ if(!user){
305
+ return redirect('/login');
306
+ }
307
+ return null;
308
+ }
309
+ ```
310
+
295
311
  ### 错误处理
296
312
 
297
313
  `routes/` 下每一层目录中,开发者同样可以定义一个 `error.tsx` 文件,默认导出一个 `<ErrorBoundary>` 组件。
@@ -6,7 +6,7 @@ sidebar_position: 2
6
6
 
7
7
  **Modern.js 的构建能力由 [Modern.js Builder](https://modernjs.dev/builder) 提供。**
8
8
 
9
- Modern.js Builder 是 Modern.js 体系的核心组件之一,它是一个面向 Web 开发场景的构建引擎,可以脱离 Modern.js 被独立使用。Modern.js Builder 同时支持 webpack 和 Rspack 等多种打包工具,默认情况下使用最成熟的 webpack 进行打包。
9
+ Modern.js Builder 是 Modern.js 体系的核心组件之一,它是一个面向 Web 开发场景的构建引擎,可以脱离 Modern.js 被独立使用。Modern.js Builder 同时支持 webpack 和 rspack 等多种打包工具,默认情况下使用最成熟的 webpack 进行打包。
10
10
 
11
11
  ## 构建架构
12
12
 
@@ -14,7 +14,7 @@ Modern.js Builder 是 Modern.js 体系的核心组件之一,它是一个面向
14
14
 
15
15
  - 上层研发框架:Modern.js。
16
16
  - 通用构建引擎:Modern.js Builder。
17
- - 底层打包工具:webpack 和 Rspack
17
+ - 底层打包工具:webpack 和 rspack
18
18
 
19
19
  <img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/builder-layers-1117.png" style={{ maxWidth: '540px' }} />
20
20
 
@@ -96,9 +96,9 @@ info File sizes after production build:
96
96
  .
97
97
  ├── asset-manifest.json
98
98
  ├── html
99
-    └── main
99
+ └── main
100
100
  ├── loader-routes
101
-    └── main
101
+ └── main
102
102
  ├── modern.config.json
103
103
  ├── route.json
104
104
  └── static
@@ -149,7 +149,7 @@ export default () => {
149
149
  然后在主应用中使用 `useModuleApp` 方法获取 `MApp` 组件, 并在主应用渲染 `MApp`。
150
150
 
151
151
  ```tsx title=主应用:App.tsx
152
- import { useModuleApp } from '@modern-js/plugin-runtime';
152
+ import { useModuleApp } from '@modern-js/plugin-garfish/runtime';
153
153
 
154
154
  function App() {
155
155
  const { MApp } = useModuleApps();
@@ -255,23 +255,23 @@ export default Index;
255
255
  ├── package.json
256
256
  ├── pnpm-lock.yaml
257
257
  ├── src
258
-    ├── components
259
-       ├── Avatar
260
-          └── index.tsx
261
-       └── Item
262
-       └── index.tsx
263
-    ├── containers
264
-       └── Contacts.tsx
265
-    ├── models
266
-       └── contacts.ts
267
-    ├── modern-app-env.d.ts
268
-    ├── routes
269
-       ├── archives
270
-          └── page.tsx
271
-       ├── layout.tsx
272
-       └── page.tsx
273
-    └── styles
274
-    └── utils.css
258
+ ├── components
259
+ ├── Avatar
260
+ └── index.tsx
261
+ └── Item
262
+ └── index.tsx
263
+ ├── containers
264
+ └── Contacts.tsx
265
+ ├── models
266
+ └── contacts.ts
267
+ ├── modern-app-env.d.ts
268
+ ├── routes
269
+ ├── archives
270
+ └── page.tsx
271
+ ├── layout.tsx
272
+ └── page.tsx
273
+ └── styles
274
+ └── utils.css
275
275
  └── tsconfig.json
276
276
  ```
277
277
 
@@ -29,29 +29,29 @@ title: 添加应用入口
29
29
  ├── package.json
30
30
  ├── pnpm-lock.yaml
31
31
  ├── src
32
-    ├── modern-app-env.d.ts
33
-    ├── landing-page
34
-       └── routes
35
-       ├── index.css
36
-       ├── layout.tsx
37
-       └── page.tsx
38
-    └── myapp
39
-    ├── components
40
-       ├── Avatar
41
-          └── index.tsx
42
-       └── Item
43
-       └── index.tsx
44
-    ├── containers
45
-       └── Contacts.tsx
46
-    ├── models
47
-       └── contacts.ts
48
-    ├── routes
49
-       ├── archives
50
-          └── page.tsx
51
-       ├── layout.tsx
52
-       └── page.tsx
53
-    └── styles
54
-    └── utils.css
32
+ ├── modern-app-env.d.ts
33
+ ├── landing-page
34
+ └── routes
35
+ ├── index.css
36
+ ├── layout.tsx
37
+ └── page.tsx
38
+ └── myapp
39
+ ├── components
40
+ ├── Avatar
41
+ └── index.tsx
42
+ └── Item
43
+ └── index.tsx
44
+ ├── containers
45
+ └── Contacts.tsx
46
+ ├── models
47
+ └── contacts.ts
48
+ ├── routes
49
+ ├── archives
50
+ └── page.tsx
51
+ ├── layout.tsx
52
+ └── page.tsx
53
+ └── styles
54
+ └── utils.css
55
55
  └── tsconfig.json
56
56
  ```
57
57
 
@@ -1,5 +0,0 @@
1
- {
2
- "label": "Commands",
3
- "position": 0,
4
- "collapsed": false
5
- }
@@ -1,39 +0,0 @@
1
- ---
2
- sidebar_position: 5
3
- ---
4
- # build
5
-
6
- ```bash
7
- Usage: modern build [options]
8
-
9
- build application
10
-
11
- Options:
12
- -c --config <config> configuration file path, which can be a relative path or an absolute path
13
- -h, --help show command help
14
- --analyze analyze the bundle and view size of each module
15
- ```
16
-
17
- `modern build` command will by default build production in `dist/`.
18
-
19
- you can configure the [`output.distPath`](/configure/app/output/dist-path) specifies the output directory for the product.
20
-
21
- ## Analyze Bundle
22
-
23
- execute `npx modern build --analyze` command,can produce an HTML file that analyzes the volume of the bundle while packaging the production code:
24
-
25
- ```
26
- Bundle Analyzer saved report to /example/dist/report.html
27
- File sizes after production build:
28
-
29
- 122.35 KB dist/static/js/885.1d4fbe5a.js
30
- 2.3 KB dist/static/js/main.4b8e8d64.js
31
- 761 B dist/static/js/runtime-main.edb7cf35.js
32
- 645 B dist/static/css/main.0dd3ecc1.css
33
- ```
34
-
35
- Open the above HTML file in the browser, you can see the tile diagram of the packaged product, and perform package volume analysis and optimization:
36
-
37
- <img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/mwa-build-analyze-8784f762c1ab0cb20935829d5f912c4c.png" />
38
-
39
- > this features based on [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer).
@@ -1,61 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- ---
4
-
5
- # dev / start
6
-
7
- ```bash
8
- Usage: modern dev / modern start [options]
9
-
10
- Development commands
11
-
12
- Options:
13
- -e --entry <entry> compiler by entry
14
- -c --config <config> configuration file path, which can be a relative path or an absolute path
15
- -h, --help show command help
16
- --analyze analyze the bundle and view size of each module
17
- --api-only only start API service
18
- ```
19
-
20
- `modern dev` start a development server,watch file change,default support React Fast Refresh:
21
-
22
- `modern start` is an alias of `modern dev` command, the usage of the two are exactly the same.
23
-
24
- ```bash
25
- $ modern dev
26
-
27
- info Starting dev server...
28
- info App running at:
29
-
30
- > Local: http://localhost:8080/
31
- > Network: http://192.168.0.1:8080/
32
- ```
33
-
34
- ## Compile Partial Pages
35
-
36
- In multi-page (MPA) projects, the `--entry` option can be added to specify one or more pages to compile. In this way, only part of the code in the project will be compiled, and the dev startup speed will be faster.
37
-
38
- For example, execute `modern dev --entry`, the entry selector will be displayed in the command line interface:
39
-
40
- ```bash
41
- $ modern dev --entry
42
-
43
- ? Please select the entry that needs to be built
44
- ❯ ◯ foo
45
- ◯ bar
46
- ◯ baz
47
- ```
48
-
49
- For example, if you select the `foo` entry, only the code related to the `foo` entry will be compiled, and the code of other pages will not be compiled.
50
-
51
- ### Specify the page by parameter
52
-
53
- You can also specify the page name through parameters after `--entry`, and the names of multiple pages can be separated by commas.
54
-
55
- ```bash
56
- # Compile foo page
57
- modern dev --entry foo
58
-
59
- # Compile foo and bar pages
60
- modern dev --entry foo,bar
61
- ```
@@ -1,61 +0,0 @@
1
- ---
2
- sidebar_position: 7
3
- ---
4
- # inspect
5
-
6
- ```
7
- Usage: modern inspect [options]
8
-
9
- Options:
10
- --env <env> view the configuration in the target environment (default: "development")
11
- --output <output> Specify the path to output in the dist (default: "/")
12
- --verbose Show the full function in the result
13
- -c --config <config> configuration file path, which can be a relative path or an absolute path
14
- -h, --help show command help
15
- ```
16
-
17
- `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.
18
-
19
- 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:
20
-
21
- - `builder.config.js`: The Modern.js Builder config to use at build time.
22
- - `webpack.config.web.js`: The webpack config used by to use at build time.
23
-
24
- ```bash
25
- ➜ npx modern inspect
26
-
27
- Inspect config succeed, open following files to view the content:
28
-
29
- - Builder Config: /root/my-project/dist/builder.config.js
30
- - Webpack Config (web): /root/my-project/dist/webpack.config.web.js
31
- ```
32
-
33
- ## Configuration Env
34
-
35
- By default, the inspect command will output the development configs, you can use the `--env production` option to output the production configs:
36
-
37
- ```bash
38
- modern inspect --env production
39
- ```
40
-
41
- ## Verbose content
42
-
43
- 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:
44
-
45
- ```bash
46
- modern inspect --verbose
47
- ```
48
-
49
- ### SSR Configuration
50
-
51
- 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.
52
-
53
- ```bash
54
- ➜ npx modern inspect
55
-
56
- Inspect config succeed, open following files to view the content:
57
-
58
- - Builder Config: /root/my-project/dist/builder.config.js
59
- - Webpack Config (web): /root/my-project/dist/webpack.config.web.js
60
- - Webpack Config (node): /root/my-project/dist/webpack.config.node.js
61
- ```
@@ -1,19 +0,0 @@
1
- ---
2
- sidebar_position: 4
3
- title: lint
4
- ---
5
- # lint
6
-
7
- ```bash
8
- Usage: modern lint [options] [...files]
9
-
10
- lint and fix source files
11
-
12
- Options:
13
- --no-fix disable auto fix source file
14
- -h, --help display help for command
15
- ```
16
-
17
- Run ESLint to check the syntax of the code. Normally, only the part of the code modified by this commit needs to be checked by `lint-staged` during the `git commit` phase.
18
-
19
- - `--no-fix` close auto fix by lint.
@@ -1,55 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- ---
4
- # new
5
-
6
- ```bash
7
- Usage: modern new [options]
8
-
9
- Execution Generator in App
10
-
11
- Options:
12
- -d, --debug using debug mode to log something (default: false)
13
- -c, --config <config> set default generator config(json string)
14
- --dist-tag <tag> use specified tag version for its generator
15
- --registry set npm registry url to run npm command
16
- -h, --help show command help
17
- ```
18
-
19
- The `modern new` command is used to enable features to an existing project.
20
-
21
- For example, add application entry, enable some optional features such as Tailwind CSS, micro frontend, etc.
22
-
23
- ### Add Entry
24
-
25
- In the project, execute the `new` command to add entries as follows:
26
-
27
- ```bash
28
- $ npx modern new
29
- ? Action Create project element
30
- ? Create project element New "entry"
31
- ? Entry name entry
32
- ```
33
-
34
- ### Enable Features
35
-
36
- In the project, execute the `new` command to enable features as follows:
37
-
38
- ```bash
39
- $ npx modern new
40
- ? Action Enable features
41
- ? Enable features (Use arrow keys)
42
- ❯ Enable Tailwind CSS
43
- Enable BFF
44
- Enable SSG
45
- Enable Micro Frontend
46
- Enable Unit Test / Integration Test
47
- Enable Visual Testing (Storybook)
48
- ```
49
-
50
- :::caution
51
- The `--config` parameter needs to use a JSON string.
52
-
53
- pnpm does not support the use of JSON strings as parameter values currently. Use `npm new` to turn on.【[Relate Issue](https://github.com/pnpm/pnpm/issues/3876)】
54
-
55
- :::
@@ -1,27 +0,0 @@
1
- ---
2
- sidebar_position: 6
3
- ---
4
- # serve
5
-
6
- ```bash
7
- Usage: modern serve [options]
8
-
9
- run server
10
-
11
- Options:
12
- -c --config <config> configuration file path, which can be a relative path or an absolute path
13
- -h, --help show command help
14
- --api-only only run API service
15
- ```
16
-
17
- Usually use the `modern serve` command to enable project run in the production environment, and you need to execute the [`build'](/apis/app/commands/build) command in advance to build the product.
18
-
19
- By default, the project will run in `localhost:8080`, you can modify the Server port number with `server.port`:
20
-
21
- ```js
22
- export default defineConfig({
23
- server: {
24
- port: 8081,
25
- },
26
- });
27
- ```
@@ -1,35 +0,0 @@
1
- ---
2
- sidebar_position: 3
3
- ---
4
- # test
5
-
6
- ```bash
7
- Usage: modern test [options]
8
-
9
- Options:
10
- -h, --help show command help
11
- ```
12
-
13
- :::caution
14
- `modern test` command need to execute the `new` command in advance to enable the `unit test/integration test`.
15
-
16
- :::
17
-
18
- `modern test` command will automatically run the test cases, the effect is as follows:
19
-
20
- ```bash
21
- $ npx modern test
22
- PASS src/tests/index.test.ts
23
- The add method
24
- ✓ should work fine. (2ms)
25
-
26
- Test Suites: 1 passed, 1 total
27
- Tests: 1 passed, 1 total
28
- Snapshots: 0 total
29
- Time: 0.994 s, estimated 1 s
30
- ```
31
-
32
- :::info
33
- files match `*.test.(js|ts)` in `api/` or `src/` will be recognized as test cases by default.
34
-
35
- :::