@modern-js/main-doc 2.32.0 → 2.32.2-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/docs/en/apis/app/runtime/app/define-config.mdx +2 -2
  3. package/docs/en/apis/app/runtime/model/auto-actions.mdx +2 -2
  4. package/docs/en/apis/app/runtime/model/model_.mdx +0 -1
  5. package/docs/en/apis/app/runtime/model/use-static-model.mdx +1 -1
  6. package/docs/en/components/enable-bff-caution.mdx +1 -1
  7. package/docs/en/configure/app/auto-load-plugin.mdx +2 -2
  8. package/docs/en/configure/app/bff/_category_.json +1 -1
  9. package/docs/en/configure/app/builder-plugins.mdx +2 -2
  10. package/docs/en/configure/app/dev/_category_.json +1 -1
  11. package/docs/en/configure/app/experiments/_category_.json +1 -1
  12. package/docs/en/configure/app/html/_category_.json +1 -1
  13. package/docs/en/configure/app/output/_category_.json +1 -1
  14. package/docs/en/configure/app/output/ssg.mdx +1 -1
  15. package/docs/en/configure/app/plugins.mdx +0 -1
  16. package/docs/en/configure/app/runtime/_category_.json +1 -1
  17. package/docs/en/configure/app/security/_category_.json +1 -1
  18. package/docs/en/configure/app/server/_category_.json +1 -1
  19. package/docs/en/configure/app/source/_category_.json +1 -1
  20. package/docs/en/configure/app/source/enable-async-entry.mdx +1 -1
  21. package/docs/en/configure/app/source/mainEntryName.mdx +1 -1
  22. package/docs/en/configure/app/testing/_category_.json +1 -1
  23. package/docs/en/configure/app/tools/_category_.json +1 -1
  24. package/docs/en/configure/app/tools/tailwindcss.mdx +45 -5
  25. package/docs/en/guides/advanced-features/bff/_category_.json +1 -1
  26. package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -2
  27. package/docs/en/guides/advanced-features/bff/function.mdx +1 -1
  28. package/docs/en/guides/advanced-features/code-split.mdx +2 -2
  29. package/docs/en/guides/advanced-features/eslint.mdx +2 -2
  30. package/docs/en/guides/advanced-features/low-level.mdx +2 -2
  31. package/docs/en/guides/advanced-features/ssg.mdx +2 -3
  32. package/docs/en/guides/advanced-features/ssr.mdx +2 -3
  33. package/docs/en/guides/advanced-features/testing.mdx +3 -3
  34. package/docs/en/guides/advanced-features/using-storybook.mdx +1 -1
  35. package/docs/en/guides/advanced-features/web-server.mdx +2 -2
  36. package/docs/en/guides/basic-features/alias.mdx +3 -3
  37. package/docs/en/guides/basic-features/css.mdx +27 -64
  38. package/docs/en/guides/basic-features/data-fetch.mdx +2 -2
  39. package/docs/en/guides/basic-features/env-vars.mdx +2 -2
  40. package/docs/en/guides/basic-features/html.mdx +0 -1
  41. package/docs/en/guides/basic-features/mock.mdx +4 -4
  42. package/docs/en/guides/basic-features/proxy.mdx +3 -3
  43. package/docs/en/guides/basic-features/routes.mdx +1 -2
  44. package/docs/en/guides/concept/builder.mdx +2 -2
  45. package/docs/en/guides/concept/entries.mdx +1 -1
  46. package/docs/en/guides/get-started/upgrade.mdx +1 -2
  47. package/docs/en/guides/topic-detail/framework-plugin/hook.mdx +2 -2
  48. package/docs/en/guides/topic-detail/generator/plugin/category.md +1 -1
  49. package/docs/en/guides/topic-detail/generator/plugin/context.md +1 -1
  50. package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +2 -2
  51. package/docs/en/guides/topic-detail/model/auto-actions.mdx +1 -1
  52. package/docs/en/guides/topic-detail/model/performance.mdx +2 -1
  53. package/docs/en/guides/topic-detail/model/typescript-best-practice.mdx +1 -1
  54. package/docs/en/guides/topic-detail/model/use-model.mdx +1 -1
  55. package/docs/en/tutorials/first-app/c05-loader.mdx +0 -2
  56. package/docs/zh/community/releases.mdx +1 -1
  57. package/docs/zh/community/team.mdx +1 -1
  58. package/docs/zh/components/enable-bff-caution.mdx +2 -2
  59. package/docs/zh/configure/app/auto-load-plugin.mdx +2 -3
  60. package/docs/zh/configure/app/bff/_category_.json +2 -2
  61. package/docs/zh/configure/app/builder-plugins.mdx +2 -3
  62. package/docs/zh/configure/app/deploy/_category_.json +1 -1
  63. package/docs/zh/configure/app/dev/_category_.json +2 -2
  64. package/docs/zh/configure/app/experiments/_category_.json +2 -2
  65. package/docs/zh/configure/app/html/_category_.json +2 -2
  66. package/docs/zh/configure/app/output/_category_.json +2 -2
  67. package/docs/zh/configure/app/output/ssg.mdx +1 -1
  68. package/docs/zh/configure/app/performance/_category_.json +1 -1
  69. package/docs/zh/configure/app/plugins.mdx +1 -2
  70. package/docs/zh/configure/app/runtime/_category_.json +2 -2
  71. package/docs/zh/configure/app/security/_category_.json +2 -2
  72. package/docs/zh/configure/app/server/_category_.json +2 -2
  73. package/docs/zh/configure/app/source/_category_.json +2 -2
  74. package/docs/zh/configure/app/testing/_category_.json +2 -2
  75. package/docs/zh/configure/app/tools/_category_.json +2 -2
  76. package/docs/zh/configure/app/tools/tailwindcss.mdx +44 -6
  77. package/docs/zh/guides/advanced-features/bff/_category_.json +1 -1
  78. package/docs/zh/guides/advanced-features/code-split.mdx +2 -2
  79. package/docs/zh/guides/advanced-features/compatibility.mdx +1 -1
  80. package/docs/zh/guides/advanced-features/eslint.mdx +1 -1
  81. package/docs/zh/guides/advanced-features/low-level.mdx +2 -2
  82. package/docs/zh/guides/advanced-features/rspack-start.mdx +0 -1
  83. package/docs/zh/guides/advanced-features/ssg.mdx +3 -4
  84. package/docs/zh/guides/advanced-features/ssr.mdx +2 -3
  85. package/docs/zh/guides/advanced-features/testing.mdx +2 -2
  86. package/docs/zh/guides/advanced-features/using-storybook.mdx +1 -1
  87. package/docs/zh/guides/advanced-features/web-server.mdx +2 -2
  88. package/docs/zh/guides/basic-features/alias.mdx +3 -3
  89. package/docs/zh/guides/basic-features/css.mdx +27 -64
  90. package/docs/zh/guides/basic-features/data-fetch.mdx +1 -2
  91. package/docs/zh/guides/basic-features/env-vars.mdx +1 -1
  92. package/docs/zh/guides/basic-features/mock.mdx +2 -2
  93. package/docs/zh/guides/basic-features/proxy.mdx +3 -3
  94. package/docs/zh/guides/basic-features/routes.mdx +1 -2
  95. package/docs/zh/guides/concept/builder.mdx +1 -1
  96. package/docs/zh/guides/concept/entries.mdx +3 -3
  97. package/docs/zh/guides/get-started/upgrade.mdx +1 -2
  98. package/modern.config.ts +8 -0
  99. package/package.json +5 -5
  100. package/src/i18n/enUS.ts +1 -1
  101. package/src/i18n/zhCN.ts +1 -1
  102. package/docs/en/configure/app/source/design-system.mdx +0 -1175
  103. package/docs/zh/configure/app/source/design-system.mdx +0 -1174
@@ -1,9 +1,8 @@
1
1
  ---
2
- title: Upgrade
3
2
  sidebar_position: 3
4
3
  ---
5
4
 
6
- # Upgrade
5
+ # Upgrading
7
6
 
8
7
  ## Upgrade with command
9
8
 
@@ -66,7 +66,7 @@ pipeline.use((count, next) => {
66
66
  return count * 2;
67
67
  });
68
68
 
69
- // 3. 执行
69
+ // 3. Run
70
70
  pipeline.run(1); // 2
71
71
  pipeline.run(5); // 6
72
72
  ```
@@ -155,7 +155,7 @@ workflow.use(count => {
155
155
  return count * 2;
156
156
  });
157
157
 
158
- // 3. 执行
158
+ // 3. Run
159
159
  workflow.run(1); // [2, 2]
160
160
  workflow.run(5); // [6, 10]
161
161
  ```
@@ -58,7 +58,7 @@ npx @modern-js/create@latest plugin --plugin @modern-js/generator-plugin-plugin
58
58
  ? Please select the base type of the plugin: Web App
59
59
  ```
60
60
 
61
- ### 自定义
61
+ ### Custom
62
62
 
63
63
  ```bash
64
64
  npx @modern-js/create@latest plugin --plugin @modern-js/generator-plugin-plugin
@@ -37,7 +37,7 @@ context.addInputBefore('packageManager', {
37
37
  properties: {
38
38
  'username': {
39
39
  type: 'string',
40
- title: '用户名',
40
+ title: 'Username',
41
41
  },
42
42
  },
43
43
  });
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  sidebar_position: 2
3
- title: development
3
+ title: Development
4
4
  ---
5
5
 
6
6
  # Experience Micro Frontend
@@ -16,7 +16,7 @@ Currently supports two routing modes
16
16
  - Self-controlled routing
17
17
  - Conventional routing
18
18
 
19
- First, clarify the routing mode of the main application [create a conventional routing main application](#创建约定式路由主应用) or [create a self-controlled routing main application](#创建自控式路由主应用)
19
+ First, clarify the routing mode of the main application [create a file-based routing main App](#file-based-routing-main-app) or [create a self-controlled main App](#self-controlled-main-app)
20
20
 
21
21
  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
22
 
@@ -23,7 +23,7 @@ function Counter() {
23
23
  const [state, actions] = useModel(countModel);
24
24
 
25
25
  useEffect(() => {
26
- // 增加 1
26
+ // Add 1
27
27
  actions.setState(state + 1);
28
28
  }, []);
29
29
  }
@@ -84,7 +84,8 @@ const fooModel = model('foo').define({
84
84
  });
85
85
 
86
86
  function ComponentA() {
87
- // 通过传入 selector 函数,只返回 a 状态给组件
87
+ // By passing in the selector function
88
+ // only the a state is returned to the component
88
89
  const [stateA] = useModel(fooModel, state => state.a);
89
90
 
90
91
  return <div>{stateA}</div>;
@@ -30,7 +30,7 @@ export const foo = model<State>('foo').define({
30
30
  });
31
31
  ```
32
32
 
33
- When you declare type information for the State of a Model, the `computed` and `actions` of the Model can get the correct type information. In fact, even if we don't define State type information in the example code above, the type information of State can be automatically inferred based on the initial value information of `state`. However, we still recommend that you declare the type information of State when defining a Model because the type information of State inferred based on the initial value information of `state` may be incomplete (missing fields or field type information), and the type information of State cannot be automatically inferred based on the initial value information of `state` when using [Function Type](/apis/app/runtime/model/model_#函数类型) to define the Model.
33
+ When you declare type information for the State of a Model, the `computed` and `actions` of the Model can get the correct type information. In fact, even if we don't define State type information in the example code above, the type information of State can be automatically inferred based on the initial value information of `state`. However, we still recommend that you declare the type information of State when defining a Model because the type information of State inferred based on the initial value information of `state` may be incomplete (missing fields or field type information), and the type information of State cannot be automatically inferred based on the initial value information of `state` when using [Function Type](/apis/app/runtime/model/model_#function-type) to define the Model.
34
34
 
35
35
  ## Dependent types of Derived State
36
36
 
@@ -39,7 +39,7 @@ const barModel = model('bar').define({
39
39
  });
40
40
 
41
41
  const [state, actions] = useModel([fooModel, barModel]);
42
- //
42
+ // Or
43
43
  const [state, actions] = useModel(fooModel, barModel);
44
44
  ```
45
45
 
@@ -78,8 +78,6 @@ function Index() {
78
78
  export default Index;
79
79
  ```
80
80
 
81
- {/* Todo 重新截图,SSR 内容 */}
82
-
83
81
  Re-execute `pnpm run dev`, view `view-source: http://localhost:8080/`, or view the "Preview" of the HTML request in the Network panel of devtools, you can see that the HTML rendered by SSR already contains the complete UI:
84
82
 
85
83
  ![display6](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/docs/11/display6.png)
@@ -24,7 +24,7 @@ Modern.js 遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/) 语义化
24
24
 
25
25
  ## 版本升级
26
26
 
27
- 当你需要升级项目中的 Modern.js 版本时,可以使用 `modern upgrade` 命令,参考 [升级](/guides/get-started/upgrade)。
27
+ 当你需要升级项目中的 Modern.js 版本时,可以使用 `modern upgrade` 命令,参考 [版本升级](/guides/get-started/upgrade)。
28
28
 
29
29
  ```bash
30
30
  npx modern upgrade
@@ -2,7 +2,7 @@
2
2
  sidebar_position: 1
3
3
  ---
4
4
 
5
- # 团队
5
+ # 开发团队
6
6
 
7
7
  Modern.js 的开发由字节跳动的 Modern.js 团队和社区贡献者驱动。
8
8
 
@@ -1,4 +1,4 @@
1
- :::caution 注意
2
- 请先在当前应用项目根目录使用【[new](/apis/app/commands#modern-new) 启用 BFF 功能。
1
+ :::tip
2
+ 请先在当前项目的根目录使用 [new 命令](/apis/app/commands#modern-new) 启用 BFF 功能。
3
3
 
4
4
  :::
@@ -1,9 +1,8 @@
1
1
  ---
2
- title: autoLoadPlugins (自动注册插件)
3
- sidebar_position: 11
2
+ sidebar_position: 22
4
3
  ---
5
4
 
6
- # autoLoadPlugins (自动注册插件)
5
+ # autoLoadPlugins 自动注册插件
7
6
 
8
7
  - **类型:** `boolean`
9
8
  - **默认值:** `false`
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "bff (BFF API)",
3
- "position": 5
2
+ "label": "bff 一体化",
3
+ "position": 2
4
4
  }
@@ -1,9 +1,8 @@
1
1
  ---
2
- title: builderPlugins (构建插件)
3
- sidebar_position: 10
2
+ sidebar_position: 21
4
3
  ---
5
4
 
6
- # builderPlugins (构建插件)
5
+ # builderPlugins 构建插件
7
6
 
8
7
  - **类型:** `BuilderPlugin[]`
9
8
  - **默认值:** `[]`
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "deploy (部署)",
2
+ "label": "deploy 部署",
3
3
  "position": 8
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "dev (开发调试)",
3
- "position": 7
2
+ "label": "dev 开发",
3
+ "position": 1
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "experiments (实验性)",
3
- "position": 15
2
+ "label": "experiments 实验性",
3
+ "position": 14
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "html (模板)",
3
- "position": 2
2
+ "label": "html 模板",
3
+ "position": 3
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "output (构建产物)",
3
- "position": 2
2
+ "label": "output 产物",
3
+ "position": 7
4
4
  }
@@ -10,7 +10,7 @@ sidebar_label: ssg
10
10
  开启**自控式路由**或**约定式路由** SSG 功能的配置。
11
11
 
12
12
  :::info 客户端路由
13
- 相关内容可以查看[路由](/guides/basic-features/routes)。
13
+ 相关内容可以查看[路由方案](/guides/basic-features/routes)。
14
14
 
15
15
  :::
16
16
 
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "performance (性能)",
2
+ "label": "performance 性能",
3
3
  "position": 13
4
4
  }
@@ -1,9 +1,8 @@
1
1
  ---
2
- title: plugins (插件)
3
2
  sidebar_position: 9
4
3
  ---
5
4
 
6
- # plugins (插件)
5
+ # plugins 插件
7
6
 
8
7
  - **类型:** `CliPlugin[]`
9
8
  - **默认值:** `[]`
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "runtime (运行时)",
3
- "position": 3
2
+ "label": "runtime 运行时",
3
+ "position": 12
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "security (安全)",
3
- "position": 14
2
+ "label": "security 安全",
3
+ "position": 11
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "server (服务器)",
3
- "position": 4
2
+ "label": "server 服务器",
3
+ "position": 6
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "source (源文件)",
3
- "position": 1
2
+ "label": "source 源文件",
3
+ "position": 5
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "testing (测试)",
3
- "position": 8
2
+ "label": "testing 测试",
3
+ "position": 10
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "label": "tools (底层配置)",
3
- "position": 12
2
+ "label": "tools 底层工具",
3
+ "position": 4
4
4
  }
@@ -14,12 +14,16 @@ const tailwind = {
14
14
  './config/html/**/*.{html,ejs,hbs}',
15
15
  './storybook/**/*',
16
16
  ],
17
- // 使用 source.designSystem 配置作为 Tailwind CSS Theme 配置
18
- theme: source.designSystem,
19
17
  };
20
18
  ```
21
19
 
22
- 对应 [TailwindCSS](https://tailwindcss.com/docs/configuration) 的配置。
20
+ 用于修改 [Tailwind CSS](https://tailwindcss.com/docs/configuration) 的配置项。
21
+
22
+ ### 启用 Tailwind CSS
23
+
24
+ 在使用 `tools.tailwindcss` 之前,你需要启用 Modern.js 的 Tailwind CSS 插件。
25
+
26
+ 请阅读[「使用 Tailwind CSS」](/guides/basic-features/css.html#使用-tailwind-css) 章节来了解开启方式。
23
27
 
24
28
  ### Function 类型
25
29
 
@@ -53,8 +57,42 @@ export default {
53
57
  };
54
58
  ```
55
59
 
56
- ### 限制
60
+ ### 注意事项
61
+
62
+ 注意:
63
+
64
+ - 如果你同时使用了 `tailwind.config.{ts,js}` 文件和 `tools.tailwindcss` 选项,那么 `tools.tailwindcss` 定义的配置会优先生效,并覆盖 `tailwind.config.{ts,js}` 中定义的内容。
65
+ - 如果你同时使用了 `source.designSystem` 配置项,那么 Tailwind CSS 的 `theme` 配置将会被 `source.designSystem` 的值所覆盖。
66
+
67
+ 其他配置的使用方式与 Tailwind CSS 官方用法一致,请参考 [tailwindcss - Configuration](https://tailwindcss.com/docs/configuration)。
68
+
69
+ ### 关于 source.designSystem
57
70
 
58
- 注意,该配置中不允许使用 `theme` 配置项,否则会构建失败。在 Modern.js 中,请使用 [source.designSystem](/configure/app/source/design-system) 作为 `Tailwind CSS Theme` 配置。
71
+ `source.designSystem` Modern.js 中废弃的配置项。
59
72
 
60
- 其他配置的使用方式和 Tailwind CSS 一致,请参考 [tailwindcss - Configuration](https://tailwindcss.com/docs/configuration)。
73
+ Modern.js vMAJOR_VERSION.33.0 版本开始,你可以使用 Tailwind CSS `theme` 配置项来代替 `source.designSystem`,不再需要将 `theme` 配置拆分并设置到 `designSystem` 上。
74
+
75
+ - 旧版本用法:
76
+
77
+ ```ts title="modern.config.ts"
78
+ const { theme, ...rest } = tailwindConfig;
79
+
80
+ export default {
81
+ tools: {
82
+ tailwindcss: rest,
83
+ },
84
+ source: {
85
+ designSystem: theme,
86
+ },
87
+ };
88
+ ```
89
+
90
+ - 当前版本用法:
91
+
92
+ ```ts title="modern.config.ts"
93
+ export default {
94
+ tools: {
95
+ tailwindcss: tailwindConfig,
96
+ },
97
+ };
98
+ ```
@@ -1,5 +1,5 @@
1
1
  {
2
- "label": "BFF",
2
+ "label": "使用 BFF",
3
3
  "position": 2,
4
4
  "link": {
5
5
  "type": "doc",
@@ -1,7 +1,7 @@
1
1
  ---
2
- title: 代码分割
3
- sidebar_position: 6
2
+ sidebar_position: 3
4
3
  ---
4
+
5
5
  # 代码分割
6
6
 
7
7
  代码分割是优化前端资源加载的一种常用手段,本文将介绍 Modern.js 支持的三种代码分割方式:
@@ -1,5 +1,5 @@
1
1
  ---
2
- sidebar_position: 5
2
+ sidebar_position: 6
3
3
  ---
4
4
 
5
5
  # 浏览器兼容性
@@ -1,7 +1,7 @@
1
1
  ---
2
- title: ESLint 规则集
3
2
  sidebar_position: 8
4
3
  ---
4
+
5
5
  # ESLint 规则集
6
6
 
7
7
  {/* 参考 [实战教程 - 确认编程环境](../handbook/c03-ide/3.1-setting-up) 确保本地 IDE 环境正常。 */}
@@ -1,7 +1,7 @@
1
1
  ---
2
- title: 配置底层工具
3
- sidebar_position: 11
2
+ sidebar_position: 10
4
3
  ---
4
+
5
5
  # 配置底层工具
6
6
 
7
7
  ## 使用方式
@@ -1,5 +1,4 @@
1
1
  ---
2
- title: 使用 Rspack
3
2
  sidebar_position: 1
4
3
  ---
5
4
 
@@ -1,9 +1,8 @@
1
1
  ---
2
- title: 静态站点生成(SSG)
3
- sidebar_position: 4
2
+ sidebar_position: 5
4
3
  ---
5
4
 
6
- # 静态站点生成(SSG)
5
+ # 静态站点生成
7
6
 
8
7
  SSG(Static Site Generation)是一种基于数据与模板,在构建时渲染完整静态网页的技术解决方案。
9
8
 
@@ -55,7 +54,7 @@ SSG 在**约定式路由**和**自控式路由**下的使用方式不同。
55
54
  - `/user/profile`
56
55
 
57
56
  :::note
58
- 如果还不了解约定式路由的规则,可以先查看[路由](/guides/basic-features/routes)。
57
+ 如果还不了解约定式路由的规则,可以先查看[路由方案](/guides/basic-features/routes)。
59
58
 
60
59
  :::
61
60
 
@@ -1,9 +1,8 @@
1
1
  ---
2
- title: 服务端渲染(SSR)
3
- sidebar_position: 3
2
+ sidebar_position: 4
4
3
  ---
5
4
 
6
- # 服务端渲染(SSR)
5
+ # 服务端渲染
7
6
 
8
7
  在 Modern.js 中,SSR 也是开箱即用的。开发者无需为 SSR 编写复杂的服务端逻辑,也无需关心 SSR 的运维,或是创建单独的服务。Modern.js 拥有完备的 SSR 降级策略,保证页面能够安全运行。
9
8
 
@@ -1,8 +1,8 @@
1
1
  ---
2
- sidebar_position: 10
2
+ sidebar_position: 11
3
3
  ---
4
4
 
5
- # 测试
5
+ # 使用 Jest 测试
6
6
 
7
7
  Modern.js 默认集成了 [Jest](https://jestjs.io/) 的测试能力。
8
8
 
@@ -1,5 +1,5 @@
1
1
  ---
2
- sidebar_position: 20
2
+ sidebar_position: 12
3
3
  ---
4
4
 
5
5
  # 使用 Storybook
@@ -1,7 +1,7 @@
1
1
  ---
2
- title: 自定义 Web Server
3
- sidebar_position: 3
2
+ sidebar_position: 13
4
3
  ---
4
+
5
5
  # 自定义 Web Server
6
6
 
7
7
  Modern.js 作为以客户端为中心的开发框架,对服务端的定制能力较弱。而在有些开发场景下,需要定制特殊的服务端逻辑,例如用户鉴权、请求预处理、添加页面渲染骨架等。
@@ -1,8 +1,8 @@
1
1
  ---
2
- title: 别名
3
- sidebar_position: 8
2
+ sidebar_position: 3
4
3
  ---
5
- # 别名
4
+
5
+ # 路径别名
6
6
 
7
7
  Modern.js 允许在 JS 和 CSS 中使用别名导入自定义目录下的模块,并内置了以下别名:
8
8
 
@@ -2,7 +2,7 @@
2
2
  sidebar_position: 2
3
3
  ---
4
4
 
5
- # CSS 开发方案
5
+ # 样式开发
6
6
 
7
7
  Modern.js 内置多种常用的 CSS 开发方案,包括 Less / Sass / Stylus 预处理器、PostCSS、CSS Modules、CSS-in-JS 和 Tailwind CSS。
8
8
 
@@ -103,47 +103,46 @@ const App = () => (
103
103
 
104
104
  :::
105
105
 
106
- ### Tailwind CSS 自动补全
107
-
108
- Tailwind CSS 官方提供了 [Tailwind CSS IntelliSense](https://github.com/tailwindlabs/tailwindcss-intellisense) 插件,用于在 VS Code 中自动补全 Tailwind CSS 的 class names、CSS functions 和 directives。
106
+ ### 配置 Tailwind CSS
109
107
 
110
- 你可以参考以下步骤来启动自动补全功能:
108
+ 在 Modern.js 中,你有两种方式来配置 Tailwind CSS:
111
109
 
112
- 1. VS Code 中安装 [Tailwind CSS IntelliSense](https://github.com/tailwindlabs/tailwindcss-intellisense) 插件。
113
- 2. 在项目的根目录创建 `tailwind.config.ts` 文件,并写入你需要的 Tailwind CSS 配置。
110
+ 1. 使用 `tailwind.config.{ts,js}` 文件,该用法与 Tailwind CSS 的官方用法一致,请参考 ["Tailwind CSS - Configuration"](https://tailwindcss.com/docs/configuration) 来了解更多用法。
114
111
 
115
112
  ```ts title="tailwind.config.ts"
113
+ import type { Config } from 'tailwindcss';
114
+
116
115
  export default {
117
- content: [
118
- './src/**/*.{js,jsx,ts,tsx}',
119
- './config/html/**/*.{html,ejs,hbs}',
120
- './storybook/**/*',
121
- ],
122
- // 主题配置(可选)
123
- theme: {},
124
- };
116
+ content: ['./src/**/*.{js,jsx,ts,tsx}'],
117
+ } as Config;
125
118
  ```
126
119
 
127
- 3. 在 `modern.config.ts` 中引用你创建的 `tailwind.config.ts` 文件,使 Modern.js 可以正确识别 Tailwind CSS 配置内容。
120
+ :::tip
121
+ 请升级 Modern.js 到 >= MAJOR_VERSION.33.0 版本,以支持自动读取 `tailwind.config.{ts,js}` 文件。
122
+ :::
128
123
 
129
- ```ts title="modern.config.ts"
130
- import tailwindConfig from './tailwind.config';
124
+ 2. 使用 [tools.tailwindcss](/configure/app/tools/tailwindcss.html) 配置项,这是旧版本的用法,我们更推荐使用 `tailwind.config.{ts,js}` 文件进行配置。
131
125
 
132
- export default defineConfig({
126
+ ```ts title="modern.config.ts"
127
+ export default {
133
128
  tools: {
134
- tailwindcss: tailwindConfig,
135
- },
136
- // 主题配置(可选)
137
- source: {
138
- designSystem: tailwindConfig.theme,
129
+ tailwindcss: {
130
+ content: ['./src/**/*.{js,jsx,ts,tsx}'],
131
+ },
139
132
  },
140
- });
133
+ };
141
134
  ```
142
135
 
143
- 请阅读相关配置项的文档来了解其作用:
136
+ 如果你同时使用了 `tailwind.config.{ts,js}` 文件和 `tools.tailwindcss` 选项,那么 `tools.tailwindcss` 定义的配置会优先生效,并覆盖 `tailwind.config.{ts,js}` 中定义的内容。
137
+
138
+ ### Tailwind CSS 自动补全
139
+
140
+ Tailwind CSS 官方提供了 [Tailwind CSS IntelliSense](https://github.com/tailwindlabs/tailwindcss-intellisense) 插件,用于在 VS Code 中自动补全 Tailwind CSS 的 class names、CSS functions 和 directives。
141
+
142
+ 你可以参考以下步骤来启动自动补全功能:
144
143
 
145
- - [tools.tailwindcss](/configure/app/tools/tailwindcss)
146
- - [source.designSystem](/configure/app/source/design-system)。
144
+ 1. 在 VS Code 中安装 [Tailwind CSS IntelliSense](https://github.com/tailwindlabs/tailwindcss-intellisense) 插件。
145
+ 2. 如果项目的根目录没有 `tailwind.config.{ts,js}` 文件,那么你需要创建该文件,并写入当前项目的 Tailwind CSS 配置,否则 IDE 插件将无法正确生效。
147
146
 
148
147
  ### Tailwind CSS 版本
149
148
 
@@ -162,39 +161,3 @@ Tailwind CSS v2 和 v3 均不支持 IE 11 浏览器,相关背景请参考:
162
161
  - [Tailwind CSS v2 - Browser Support](https://v2.tailwindcss.com/docs/browser-support)
163
162
 
164
163
  如果你在 IE 11 浏览器上使用 Tailwind CSS,可能会出现部分样式不可用的现象,请谨慎使用。
165
-
166
- ### Theme 配置
167
-
168
- 当需要自定义 Tailwind CSS 的 [theme](https://tailwindcss.com/docs/theme) 配置的时候,可以在配置 [`source.designSystem`](/configure/app/source/design-system) 中修改,例如,颜色主题中增加一个 `primary`:
169
-
170
- ```ts title="modern.config.ts"
171
- export default defineConfig({
172
- source: {
173
- designSystem: {
174
- extend: {
175
- colors: {
176
- primary: '#5c6ac4',
177
- },
178
- },
179
- },
180
- },
181
- });
182
- ```
183
-
184
- 当需要对 Tailwind CSS 做 [theme](https://tailwindcss.com/docs/theme) 以外的其他特殊配置时,可以在 [`tools.tailwindcss`](/configure/app/tools/tailwindcss) 中配置,例如设置 `variants`:
185
-
186
- ```ts title="modern.config.ts"
187
- export default defineConfig({
188
- tools: {
189
- tailwindcss: {
190
- variants: {
191
- extend: {
192
- backgroundColor: ['active'],
193
- },
194
- },
195
- },
196
- },
197
- });
198
- ```
199
-
200
- > 当你为项目配置 Tailwind CSS 的时候,[source.designSystem](/configure/app/source/design-system) 和 [tools.tailwindcss](/configure/app/tools/tailwindcss) 这两个配置的组合等价于单独配置了一个 `tailwindcss.config.js` 文件。其中 [source.designSystem](/configure/app/source/design-system) 等效于 Tailwind CSS 的 [theme](https://v2.tailwindcss.com/docs/configuration#theme) 配置。
@@ -1,6 +1,5 @@
1
1
  ---
2
- title: 数据获取
3
- sidebar_position: 3
2
+ sidebar_position: 4
4
3
  ---
5
4
 
6
5
  # 数据获取
@@ -1,7 +1,7 @@
1
1
  ---
2
- title: 环境变量
3
2
  sidebar_position: 7
4
3
  ---
4
+
5
5
  # 环境变量
6
6
 
7
7
  Modern.js 提供了对环境变量的支持,包含内置的环境变量和自定义的环境变量。