@modern-js/main-doc 2.5.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) 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/config/upload.mdx +10 -0
  5. package/en/apis/app/hooks/src/routes.mdx +2 -2
  6. package/en/components/init-app.mdx +5 -5
  7. package/en/configure/app/bff/prefix.mdx +2 -3
  8. package/en/configure/app/bff/proxy.mdx +1 -1
  9. package/en/configure/app/dev/before-start-url.mdx +13 -0
  10. package/en/configure/app/dev/host.mdx +13 -0
  11. package/en/configure/app/output/ssg.mdx +3 -3
  12. package/en/configure/app/runtime/master-app.mdx +1 -1
  13. package/en/configure/app/server/ssr.mdx +18 -0
  14. package/en/configure/app/source/entries-dir.mdx +1 -1
  15. package/en/configure/app/testing/transformer.mdx +1 -1
  16. package/en/configure/app/tools/jest.mdx +1 -1
  17. package/en/guides/advanced-features/rspack-start.mdx +69 -0
  18. package/en/guides/advanced-features/ssg.mdx +8 -8
  19. package/en/guides/advanced-features/ssr.mdx +210 -5
  20. package/en/guides/basic-features/alias.mdx +4 -4
  21. package/en/guides/{css/tailwindcss.mdx → basic-features/css.mdx} +60 -3
  22. package/en/guides/basic-features/data-fetch.mdx +4 -4
  23. package/en/guides/basic-features/env-vars.mdx +4 -0
  24. package/en/guides/basic-features/routes.mdx +23 -7
  25. package/en/guides/concept/builder.mdx +1 -1
  26. package/en/guides/get-started/quick-start.mdx +2 -2
  27. package/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +1 -1
  28. package/en/tutorials/first-app/c03-css.mdx +1 -1
  29. package/en/tutorials/first-app/c07-container.mdx +17 -17
  30. package/en/tutorials/first-app/c08-entries.mdx +23 -23
  31. package/package.json +3 -3
  32. package/scripts/summary.en.json +1 -1
  33. package/scripts/summary.zh.json +1 -1
  34. package/zh/apis/app/commands.mdx +299 -0
  35. package/zh/apis/app/hooks/_category_.json +1 -1
  36. package/zh/apis/app/hooks/config/upload.mdx +12 -2
  37. package/zh/apis/app/hooks/src/routes.mdx +2 -2
  38. package/zh/components/init-app.mdx +5 -5
  39. package/zh/configure/app/bff/prefix.mdx +1 -1
  40. package/zh/configure/app/bff/proxy.mdx +1 -1
  41. package/zh/configure/app/dev/before-start-url.mdx +13 -0
  42. package/zh/configure/app/dev/host.mdx +13 -0
  43. package/zh/configure/app/output/ssg.mdx +3 -3
  44. package/zh/configure/app/server/ssr.mdx +19 -1
  45. package/zh/configure/app/source/entries-dir.mdx +1 -1
  46. package/zh/guides/advanced-features/rspack-start.mdx +69 -0
  47. package/zh/guides/advanced-features/ssg.mdx +8 -8
  48. package/zh/guides/advanced-features/ssr.mdx +213 -6
  49. package/zh/guides/basic-features/alias.mdx +4 -4
  50. package/zh/guides/{css/tailwindcss.mdx → basic-features/css.mdx} +60 -3
  51. package/zh/guides/basic-features/data-fetch.mdx +4 -4
  52. package/zh/guides/basic-features/env-vars.mdx +4 -0
  53. package/zh/guides/basic-features/routes.mdx +23 -7
  54. package/zh/guides/concept/builder.mdx +2 -2
  55. package/zh/guides/get-started/quick-start.mdx +2 -2
  56. package/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +1 -1
  57. package/zh/tutorials/first-app/c03-css.mdx +1 -1
  58. package/zh/tutorials/first-app/c07-container.mdx +17 -17
  59. package/zh/tutorials/first-app/c08-entries.mdx +23 -23
  60. package/en/apis/app/commands/_category_.json +0 -5
  61. package/en/apis/app/commands/build.mdx +0 -39
  62. package/en/apis/app/commands/dev.mdx +0 -61
  63. package/en/apis/app/commands/inspect.mdx +0 -61
  64. package/en/apis/app/commands/lint.mdx +0 -19
  65. package/en/apis/app/commands/new.mdx +0 -55
  66. package/en/apis/app/commands/serve.mdx +0 -27
  67. package/en/apis/app/commands/test.mdx +0 -35
  68. package/en/apis/app/commands/upgrade.mdx +0 -18
  69. package/en/guides/css/_category_.json +0 -5
  70. package/en/guides/css/css-in-js.mdx +0 -40
  71. package/en/guides/css/css-modules.mdx +0 -87
  72. package/en/guides/css/less-sass.mdx +0 -17
  73. package/en/guides/css/postcss.mdx +0 -79
  74. package/zh/apis/app/commands/_category_.json +0 -5
  75. package/zh/apis/app/commands/build.mdx +0 -39
  76. package/zh/apis/app/commands/dev.mdx +0 -61
  77. package/zh/apis/app/commands/inspect.mdx +0 -61
  78. package/zh/apis/app/commands/lint.mdx +0 -19
  79. package/zh/apis/app/commands/new.mdx +0 -54
  80. package/zh/apis/app/commands/serve.mdx +0 -27
  81. package/zh/apis/app/commands/test.mdx +0 -35
  82. package/zh/apis/app/commands/upgrade.mdx +0 -18
  83. package/zh/guides/css/_category_.json +0 -5
  84. package/zh/guides/css/css-in-js.mdx +0 -40
  85. package/zh/guides/css/css-modules.mdx +0 -87
  86. package/zh/guides/css/less-sass.mdx +0 -17
  87. package/zh/guides/css/postcss.mdx +0 -80
@@ -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
- 运行 `ESLint` 检查代码语法情况。通常情况下,我们只需要在 `git commit` 阶段通过 `lint-staged` 检查本次提交修改的部分代码。
18
-
19
- - `--no-fix` 参数设置后可以关闭自动修复 lint 错误代码的能力。
@@ -1,54 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- ---
4
- # new
5
-
6
- ```bash
7
- Usage: modern new [options]
8
-
9
- 应用工程中执行生成器
10
-
11
- Options:
12
- -d, --debug 开启 Debug 模式,打印调试日志信息 (default: false)
13
- -c, --config <config> 生成器运行默认配置(JSON 字符串)
14
- --dist-tag <tag> 生成器使用特殊的 npm Tag 版本
15
- --registry 生成器运行过程中定制 npm Registry
16
- -h, --help 显示命令帮助
17
- ```
18
-
19
- `modern new` 命令用于在已有项目中添加项目元素。
20
-
21
- 比如添加应用入口、启用启用一些可选功能如 Tailwind CSS、微前端开发模式等。
22
-
23
- ### 添加入口
24
-
25
- 在应用工程中,执行 `new` 命令添加入口如下:
26
-
27
- ```bash
28
- $ npx modern new
29
- ? 请选择你想要的操作 创建工程元素
30
- ? 创建工程元素 新建「应用入口」
31
- ? 请填写入口名称 entry
32
- ```
33
-
34
- ### 启用可选功能
35
-
36
- 在应用工程中,执行 `new` 命令启用可选能力如下:
37
-
38
- ```bash
39
- $ npx modern new
40
- ? 请选择你想要的操作 启用可选功能
41
- ? 启用可选功能 (Use arrow keys)
42
- ❯ 启用 Tailwind CSS 支持
43
- 启用「BFF」功能
44
- 启用「微前端」模式
45
- 启用「单元测试 / 集成测试」功能
46
- 启用「Visual Testing (Storybook)」模式
47
- ```
48
-
49
- :::caution 注意
50
- `--config` 参数对应参数值需要使用 JSON 字符串。
51
-
52
- pnpm 暂不支持使用 JSON 字符串作为参数值,可使用 `npm new` 开启相关功能。【[相关 Issue](https://github.com/pnpm/pnpm/issues/3876)】
53
-
54
- :::
@@ -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> 指定配置文件路径,可以为相对路径或绝对路径
13
- -h, --help 显示命令帮助
14
- --api-only 仅启动 API 接口服务
15
- ```
16
-
17
- 通常使用 `modern serve` 命令在生产环境下启用应用工程, 需要提前执行 [`build`](/apis/app/commands/build) 命令构建出对应产物。
18
-
19
- 默认情况下,应用将会在 `localhost:8080` 启动,可以通过 `server.port` 修改 Server 端口号:
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 显示命令帮助
11
- ```
12
-
13
- :::caution 注意
14
- `modern test` 命令需要先通过 [`new`](/apis/app/commands/new) 命令启用「单元测试 / 集成测试」功能
15
-
16
- :::
17
-
18
- `modern test` 命令会自动运行项目下的测试用例,效果如下:
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
- `src` 和 `api` 目录下面 `*.test.(js|ts)` 都会默认识别为测试用例。
34
-
35
- :::
@@ -1,18 +0,0 @@
1
- ---
2
- sidebar_position: 8
3
- ---
4
- # upgrade
5
-
6
- ```
7
- Usage: modern upgrade [options]
8
-
9
- 升级 Modern.js 到最新版本
10
-
11
- Options:
12
- --registry <registry> 定制 npm registry (default: "")
13
- -d,--debug 开启 Debug 模式,打印调试日志信息 (default: false)
14
- --cwd <cwd> 项目路径 (default: "")
15
- -h, --help display help for command
16
- ```
17
-
18
- 在项目根目录下执行命令 `npx modern upgrade`,会默认将当前执行命令项目的 `package.json` 中的 Modern.js 相关依赖更新至最新版本。
@@ -1,5 +0,0 @@
1
- {
2
- "label": "CSS 开发方案",
3
- "position": 5,
4
- "collapsed": false
5
- }
@@ -1,40 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- ---
4
-
5
- # CSS-in-JS
6
-
7
- CSS-in-JS 是一种可以将 CSS 样式写在 JS 文件里的技术。Modern.js 集成了社区常用的 CSS-in-JS 实现库 [styled-components](https://styled-components.com/),它使用 JavaScript 的新特性 [Tagged template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) 编写组件的 CSS 样式。可以直接从 `@modern-js/runtime/styled` 引入 [styled-components](https://styled-components.com/) 的 API 进行使用。
8
-
9
- 当需要编写一个内部字体为红色的 `div` 组件时,可以如下实现:
10
-
11
- ```js
12
- import styled from '@modern-js/runtime/styled';
13
-
14
- const RedDiv = styled.div`
15
- color: red;
16
- `;
17
- ```
18
-
19
- 当需要根据组件的 `props` 动态设置组件样式时,例如 `props` 的属性 `primary` 为 `true` 时,按钮的颜色为白色,其他情况为红色,实现代码如下:
20
-
21
- ```js
22
- import styled from '@modern-js/runtime/styled';
23
-
24
- const Button = styled.button`
25
- color: ${props => (props.primary ? 'white' : 'red')};
26
- font-size: 1em;
27
- `;
28
- ```
29
-
30
- 关于 styled-components 的更多用法,请参考【[styled-components 官网](https://styled-components.com/)】。
31
-
32
- :::info 补充信息
33
- Modern.js 内部使用了 Babel 插件 [babel-plugin-styled-components](https://github.com/styled-components/babel-plugin-styled-components),可以通过 [`tools.styledComponents`](/configure/app/tools/styled-components) 对插件进行配置。
34
-
35
- :::
36
-
37
- :::tip 提示
38
- 如果需要使用 [styled-jsx](https://www.npmjs.com/package/styled-jsx)、[Emotion](https://emotion.sh/) 等其他 CSS-in-JS 库,需要先安装对应库的依赖。具体使用方式请参考对应库的官网。
39
-
40
- :::
@@ -1,87 +0,0 @@
1
- ---
2
- sidebar_position: 5
3
- ---
4
-
5
- # CSS Modules
6
-
7
- Modern.js 为 [CSS Modules](https://github.com/css-modules/css-modules) 提供了开箱即用的支持。
8
-
9
- ## 文件后缀形式 CSS Modules
10
-
11
- 默认情况下,以 `.module.(css|scss|sass|less)` 结尾的文件会作为 CSS Modules 文件处理,例如:
12
-
13
- ```css title="button.module.css"
14
- .redColor {
15
- color: red;
16
- }
17
- ```
18
-
19
- ```js title="Button.jsx"
20
- import styles from './button.module.css';
21
-
22
- export default function Button() {
23
- return (
24
- <button type="button" className={styles.redColor}>
25
- red button
26
- </button>
27
- );
28
- }
29
- ```
30
-
31
- 最终将被编译为
32
-
33
- ```js
34
- <button type="button" className="button_redColor__1-RBg">
35
- red button
36
- </button>
37
- ```
38
-
39
- ## 全面启用 CSS Modules
40
-
41
- 如果想去掉文件名中 `.module` 后缀,可以设置 [`output.disableCssModuleExtension`](/configure/app/output/disable-css-module-extension)。
42
-
43
- 设置后,除了 `node_modules/` 目录下的样式文件和文件名称格式为 `[name].global.(css|scss|sass|less)` 之外的所有样式文件,都会作为 CSS Modules 处理。
44
-
45
- 如果此时需要全局样式,可以通过创建文件名称格式为 `[name].global.(css|less|scss|sass)` 的样式文件来解决, 例如:
46
-
47
- ```css title="app.global.css"
48
- .bg-blue {
49
- background-color: blue;
50
- }
51
- ```
52
-
53
- ```css title="button.css"
54
- .redColor {
55
- color: red;
56
- }
57
- ```
58
-
59
- ```js title="App.jsx"
60
- import './app.global.css';
61
- import styles from './button.css';
62
-
63
- export default function Button() {
64
- return (
65
- <button type="button" className={`${styles.redColor} bg-blue`}>
66
- button
67
- </button>
68
- );
69
- }
70
- ```
71
-
72
- 最终将被编译为:
73
-
74
- ```js
75
- <button type="button" className="button__redColor--JsFYl bg-blue">
76
- button
77
- </button>
78
- ```
79
-
80
- 最终效果如下:
81
-
82
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/more-css-modules.png)
83
-
84
- :::tip 提示
85
- 使用 [babel-plugin-react-css-modules](https://github.com/gajus/babel-plugin-react-css-modules) 时需要注意,该插件的配置选项 `generateScopedName` 需要和 [`output.cssModuleLocalIdentName`](/configure/app/output/css-module-local-ident-name) 保持一致。
86
-
87
- :::
@@ -1,17 +0,0 @@
1
- ---
2
- sidebar_position: 4
3
- ---
4
-
5
- # Less 和 Sass
6
-
7
- [Less](https://lesscss.org/) 和 [Sass](https://sass-lang.com/) 是常用的两种 CSS 预处理器,Modern.js 内置了 Less 和 Sass 编译能力的支持。
8
-
9
- ## 自定义配置
10
-
11
- - 如果需要自定义 [less-loader](https://github.com/webpack-contrib/less-loader) 的配置,请参考 [tools.less](/configure/app/tools/less) 配置项。
12
- - 如果需要自定义 [sass-loader](https://github.com/webpack-contrib/sass-loader) 的配置,请参考 [tools.less](/configure/app/tools/sass) 配置项。
13
-
14
- :::tip 提示
15
- 经过 Less 和 Sass 预编译后的 CSS 文件,仍然会经过 Modern.js 内置的 [PostCSS](https://postcss.org/) 的转换,具备良好的浏览器兼容性。相关内容请参考【[PostCSS](/guides/css/postcss)】。
16
-
17
- :::
@@ -1,80 +0,0 @@
1
- ---
2
- sidebar_position: 3
3
- ---
4
-
5
- # PostCSS
6
-
7
- [PostCSS](https://postcss.org/) 是一个用 JavaScript 工具和插件转换 CSS 代码的工具。Modern.js 内置 PostCSS,并集成 [Autoprefixer](https://github.com/postcss/autoprefixer) 等常用的 PostCSS 插件,能够满足大多数项目的样式开发需求。
8
-
9
- 默认情况下,Modern.js 会对 CSS 进行以下编译和转换:
10
-
11
- 1. [Autoprefixer](https://github.com/postcss/autoprefixer) 根据需要支持的浏览器范围,会自动为 CSS 规则添加需要的浏览器厂商前缀。Modern.js 默认支持的浏览器范围为:`['> 0.01%', 'not dead', 'not op_mini all']`。
12
-
13
- :::info 注意
14
-
15
- - 【支持的浏览器范围为:`> 0.01%`】是指浏览器市场份额大于 0.01%。
16
- - `not dead` 是指不包含官方不再支持的浏览器和过去 24 个月没有更新的浏览器。
17
- - `not op_mini all` 是指不包含 Opera Mini。
18
-
19
- :::
20
-
21
- :::info 补充信息
22
- 如果需要修改默认浏览器支持范围,可以在项目的 `package.json` 文件中配置 `browserslist`,设置规则参考 [Browserslist](https://github.com/browserslist/browserslist) 的使用,下面是一个示例:
23
- `json title="package.json" { "browserslist": [ "last 1 version", "> 1%", "IE 10" ] } `
24
-
25
- :::
26
-
27
- 2. 提供 [CSS custom properties](https://www.w3.org/TR/css-variables-1/) 支持,可以在 CSS 中定义和使用自定义变量,如:
28
-
29
- ```css
30
- :root {
31
- --main-bg-color: pink;
32
- }
33
-
34
- body {
35
- background-color: var(--main-bg-color);
36
- }
37
- ```
38
-
39
- 3. 提供 [CSS Nesting](https://drafts.csswg.org/css-nesting-1/) 支持,可以在 CSS 中使用嵌套写法,如:
40
-
41
- ```css
42
- table.colortable td {
43
- text-align: center;
44
- }
45
- table.colortable td.c {
46
- text-transform: uppercase;
47
- }
48
- ```
49
-
50
- 也可以改写成 CSS 嵌套写法:
51
-
52
- ```css
53
- table.colortable {
54
- & td {
55
- text-align: center;
56
- &.c {
57
- text-transform: uppercase;
58
- }
59
- }
60
- }
61
- ```
62
-
63
- 4. 修复已知的 [Flexbugs](https://github.com/philipwalton/flexbugs) 。
64
- 5. 对以下 CSS 特性提供兼容:
65
- - [`initial` 属性值](https://developer.mozilla.org/en-US/docs/Web/CSS/initial_value)
66
- - [`break-` 属性](https://developer.mozilla.org/en-US/docs/Web/CSS/break-after)
67
- - [`font-variant`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant)
68
- - [Media Query Ranges](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries#syntax_improvements_in_level_4)
69
-
70
- 当需要修改 PostCSS 配置时,可以通过底层配置 [`tools.postcss`](/configure/app/tools/postcss) 来实现,下面是一个示例:
71
-
72
- ```ts title="modern.config.ts"
73
- export default defineConfig({
74
- tools: {
75
- postcss: {
76
- plugins: ['autoprefixer', ('postcss-flexbugs-fixes': {})],
77
- },
78
- },
79
- });
80
- ```