@modern-js/module-tools-docs 2.32.1 → 2.33.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 (39) hide show
  1. package/.eslintrc.js +1 -1
  2. package/CHANGELOG.md +11 -0
  3. package/docs/en/api/config/build-config.mdx +17 -16
  4. package/docs/en/api/config/build-preset.mdx +11 -72
  5. package/docs/en/guide/advance/asset.mdx +1 -1
  6. package/docs/en/guide/advance/copy.md +17 -18
  7. package/docs/en/guide/advance/external-dependency.mdx +1 -1
  8. package/docs/en/guide/advance/in-depth-about-build.md +27 -28
  9. package/docs/en/guide/advance/in-depth-about-dev-command.md +1 -1
  10. package/docs/en/guide/basic/before-getting-started.md +1 -1
  11. package/docs/en/guide/basic/modify-output-product.md +44 -70
  12. package/docs/en/guide/basic/test-your-project.mdx +0 -2
  13. package/docs/en/guide/basic/use-micro-generator.md +12 -37
  14. package/docs/en/guide/basic/using-storybook.mdx +15 -0
  15. package/docs/en/guide/best-practices/components.mdx +5 -198
  16. package/docs/en/guide/best-practices/use-tailwindcss.mdx +289 -0
  17. package/docs/en/plugins/guide/setup-function.mdx +0 -1
  18. package/docs/zh/api/config/build-config.mdx +19 -20
  19. package/docs/zh/api/config/build-preset.mdx +12 -69
  20. package/docs/zh/guide/advance/asset.mdx +3 -6
  21. package/docs/zh/guide/advance/copy.md +0 -2
  22. package/docs/zh/guide/advance/external-dependency.mdx +1 -1
  23. package/docs/zh/guide/advance/in-depth-about-build.md +30 -56
  24. package/docs/zh/guide/basic/before-getting-started.md +1 -1
  25. package/docs/zh/guide/basic/modify-output-product.md +46 -69
  26. package/docs/zh/guide/basic/use-micro-generator.md +13 -33
  27. package/docs/zh/guide/basic/using-storybook.mdx +16 -5
  28. package/docs/zh/guide/best-practices/components.mdx +1 -196
  29. package/docs/zh/guide/best-practices/use-tailwindcss.mdx +289 -0
  30. package/docs/zh/plugins/guide/setup-function.mdx +0 -1
  31. package/package.json +7 -6
  32. package/rspress.config.ts +130 -0
  33. package/theme/index.ts +3 -2
  34. package/tsconfig.json +1 -1
  35. package/docs/en/api/config/design-system.md +0 -1166
  36. package/docs/en/guide/advance/theme-config.mdx +0 -60
  37. package/docs/zh/api/config/design-system.md +0 -1166
  38. package/docs/zh/guide/advance/theme-config.mdx +0 -64
  39. package/modern.config.ts +0 -124
@@ -0,0 +1,289 @@
1
+ ---
2
+ sidebar_position: 2
3
+ ---
4
+
5
+ # 使用 Tailwind CSS
6
+
7
+ [Tailwind CSS](https://tailwindcss.com/) 是一个以 Utility Class 为基础的 CSS 框架和设计系统,可以快速地为组件添加常用样式,同时支持主题样式的灵活扩展。
8
+
9
+ Module Tools 支持使用 Tailwind CSS 开发组件样式。
10
+
11
+ ## 启用 Tailwind CSS
12
+
13
+ 默认情况下,Module Tools 没有开启该功能,需要按照下面的方式开启它。
14
+
15
+ 1. 在项目根目录下执行 `new` 命令,可以开启 Tailwind CSS 功能。
16
+
17
+ ```text title="终端"
18
+ pnpm run new
19
+
20
+ ? 请选择你想要的操作:启用可选功能
21
+ ? 请选择功能名称:启用 「Tailwind CSS」 支持
22
+ ```
23
+
24
+ 2. 成功开启后,会看到 `package.json` 中新增了依赖。
25
+
26
+ ```json title="./package.json"
27
+ {
28
+ "devDependencies": {
29
+ "@modern-js/plugin-tailwindcss": "x.y.z"
30
+ }
31
+ }
32
+ ```
33
+
34
+ 3. 最后,需要手动在配置文件中注册 `tailwindcssPlugin`:
35
+
36
+ ```ts title="modern.config.ts"
37
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
38
+ import { tailwindcssPlugin } from '@modern-js/plugin-tailwindcss';
39
+
40
+ export default defineConfig({
41
+ plugins: [moduleTools(), tailwindPlugin()],
42
+ });
43
+ ```
44
+
45
+ ## 配置 Tailwind CSS
46
+
47
+ 在 Module Tools 中,你有两种方式来配置 Tailwind CSS:
48
+
49
+ 1. 使用 `tailwind.config.{ts,js}` 文件,该用法与 Tailwind CSS 的官方用法一致,请参考 ["Tailwind CSS - Configuration"](https://tailwindcss.com/docs/configuration) 来了解更多用法。
50
+
51
+ ```ts title="tailwind.config.ts"
52
+ import type { Config } from 'tailwindcss';
53
+
54
+ export default {
55
+ content: ['./src/**/*.{js,jsx,ts,tsx}'],
56
+ } as Config;
57
+ ```
58
+
59
+ :::tip
60
+ 请升级 Module Tools 到 >= MAJOR_VERSION.33.0 版本,以支持自动读取 `tailwind.config.{ts,js}` 文件。
61
+ :::
62
+
63
+ 2. 使用 [style.tailwindcss](/api/config/build-config.html#styletailwindcss) 配置项,这是旧版本的用法,我们更推荐使用 `tailwind.config.{ts,js}` 文件进行配置。
64
+
65
+ ```ts title="modern.config.ts"
66
+ export default {
67
+ style: {
68
+ tailwindcss: {
69
+ content: ['./src/**/*.{js,jsx,ts,tsx}'],
70
+ },
71
+ },
72
+ };
73
+ ```
74
+
75
+ 如果你同时使用了 `tailwind.config.{ts,js}` 文件和 `style.tailwindcss` 选项,那么 `style.tailwindcss` 定义的配置会优先生效,并覆盖 `tailwind.config.{ts,js}` 中定义的内容。
76
+
77
+ ## Tailwind CSS 自动补全
78
+
79
+ Tailwind CSS 官方提供了 [Tailwind CSS IntelliSense](https://github.com/tailwindlabs/tailwindcss-intellisense) 插件,用于在 VS Code 中自动补全 Tailwind CSS 的 class names、CSS functions 和 directives。
80
+
81
+ 你可以参考以下步骤来启动自动补全功能:
82
+
83
+ 1. 在 VS Code 中安装 [Tailwind CSS IntelliSense](https://github.com/tailwindlabs/tailwindcss-intellisense) 插件。
84
+ 2. 如果项目的根目录没有 `tailwind.config.{ts,js}` 文件,那么你需要创建该文件,并写入当前项目的 Tailwind CSS 配置,否则 IDE 插件将无法正确生效。
85
+
86
+ ## 用法介绍
87
+
88
+ Tailwind CSS 提供了两种使用方式:
89
+
90
+ ### HTML 类名
91
+
92
+ Tailwind CSS 支持在 HTML 标签上使用类名的方式增加样式。**当使用 HTML 类名的时候,一定要注意导入 Tailwind CSS 相应的 css 文件。**
93
+
94
+ ```tsx title="./src/index.tsx"
95
+ import 'tailwindcss/utilities.css';
96
+
97
+ export default () => {
98
+ return <div className="bg-black text-white">hello world</div>;
99
+ };
100
+ ```
101
+
102
+ 样式产物(此时是 bundle 构建):
103
+
104
+ ```css title="./dist/es/index.css"
105
+ /* node_modules/tailwindcss/utilities.css */
106
+ .table {
107
+ display: table;
108
+ }
109
+ .bg-black {
110
+ --tw-bg-opacity: 1;
111
+ background-color: rgba(0, 0, 0, var(--tw-bg-opacity));
112
+ }
113
+ .text-white {
114
+ --tw-text-opacity: 1;
115
+ color: rgba(255, 255, 255, var(--tw-text-opacity));
116
+ }
117
+ /** some more... */
118
+ ```
119
+
120
+ ### `@apply`
121
+
122
+ Tailwind CSS 提供了 [`@apply`](https://v2.tailwindcss.com/docs/functions-and-directives#apply) 指令,可以通过它将 Tailwind CSS 提供的样式内联到我们编写的样式中。
123
+
124
+ `@apply` 可以用于 CSS、Less、Sass 中。
125
+
126
+ ```css
127
+ .btn {
128
+ @apply font-bold py-2 px-4 rounded;
129
+ }
130
+ ```
131
+
132
+ 但是使用过程中,对于 Less 和 Sass 有些情况需要注意:
133
+
134
+ #### Sass
135
+
136
+ 当将 Tailwind 与 Sass 一起使用时,`@apply` 后面存在 `!important` 的时候,需要使用插值来让 Sass 正确编译。
137
+
138
+ - 不能正常工作:
139
+
140
+ ```sass
141
+ .alert {
142
+ @apply bg-red-500 !important;
143
+ }
144
+ ```
145
+
146
+ - 能够正常工作:
147
+
148
+ ```sass
149
+ .alert {
150
+ @apply bg-red-500 #{!important};
151
+ }
152
+ ```
153
+
154
+ #### Less
155
+
156
+ 在与 Less 一起使用 Tailwind 时,你不能嵌套 Tailwind 的 `@screen` 指令。
157
+
158
+ - 不能正常工作:
159
+
160
+ ```less
161
+ .card {
162
+ @apply rounded-none;
163
+
164
+ @screen sm {
165
+ @apply rounded-lg;
166
+ }
167
+ }
168
+ ```
169
+
170
+ - 相反,使用常规的媒体查询和 `theme()` 函数来引用你的屏幕尺寸,或者干脆不要嵌套你的 `@screen` 指令。
171
+
172
+ ```less title="方法一"
173
+ // Use a regular media query and theme()
174
+ .card {
175
+ @apply rounded-none;
176
+
177
+ @media (min-width: theme('screens.sm')) {
178
+ @apply rounded-lg;
179
+ }
180
+ }
181
+ ```
182
+
183
+ ```less title="方法二"
184
+ // Use the @screen directive at the top-level
185
+ .card {
186
+ @apply rounded-none;
187
+
188
+ @media (min-width: theme('screens.sm')) {
189
+ @apply rounded-lg;
190
+ }
191
+ }
192
+ ```
193
+
194
+ ### 推荐方式
195
+
196
+ **推荐使用 `@apply` 指定的方式开发样式,这样在样式产物中仅包含通过指令内联的样式。**
197
+
198
+ 当使用 HTML 类名的方式添加样式的时候,默认情况下 Tailwind 不仅会将本身类名对应的样式加入产物中,同时还会有额外的样式代码存在,虽然这些代码可能不会对本身的样式产生影响。
199
+
200
+ ### bundle 和 bundleless 构建产物区别
201
+
202
+ 对于以下代码,在 bundle 和 bundleless 两种模式下,构建产物会有很大区别。
203
+
204
+ > 所谓 bundle 和 bundleless 可以查看 [「Bundle 和 Bundleless」](/guide/advance/in-depth-about-build#bundle-和-bundleless)
205
+
206
+ ```tsx title="./src/index.tsx"
207
+ import 'tailwindcss/utilities.css';
208
+
209
+ export default () => {
210
+ return <div className="bg-black text-white">hello world11</div>;
211
+ };
212
+ ```
213
+
214
+ Bundle 模式下,会将第三方依赖打包进来。
215
+
216
+ 对于样式则会生成一份单独的产物文件,并且在 JS 产物文件中并不会存在导入样式的相关代码。
217
+
218
+ 如果需要将样式注入 JS 产物中,可以开启 [`style.inject`](/api/config/build-config#styleinject) 选项。
219
+
220
+ ```css title="./dist/es/index.css"
221
+ /* node_modules/tailwindcss/utilities.css */
222
+ .table {
223
+ display: table;
224
+ }
225
+ .bg-black {
226
+ --tw-bg-opacity: 1;
227
+ background-color: rgba(0, 0, 0, var(--tw-bg-opacity));
228
+ }
229
+ .text-white {
230
+ --tw-text-opacity: 1;
231
+ color: rgba(255, 255, 255, var(--tw-text-opacity));
232
+ }
233
+ /** some more... */
234
+ ```
235
+
236
+ ```js title="./dist/es/index.js"
237
+ // src/index.tsx
238
+ import { jsx } from 'react/jsx-runtime';
239
+ var src_default = () => {
240
+ return /* @__PURE__ */ jsx('div', {
241
+ className: 'bg-black text-white',
242
+ children: 'hello world11',
243
+ });
244
+ };
245
+ export { src_default as default };
246
+ ```
247
+
248
+ Bundleless 模式下,并不会将第三方依赖打包进来,此时不会有样式产物生成。
249
+
250
+ ```js title="./dist/es/index.js"
251
+ import { jsx } from 'react/jsx-runtime';
252
+ import 'tailwindcss/utilities.css';
253
+ var src_default = () => {
254
+ return /* @__PURE__ */ jsx('div', {
255
+ className: 'bg-black text-white',
256
+ children: 'hello world11',
257
+ });
258
+ };
259
+ export { src_default as default };
260
+ ```
261
+
262
+ ### 关于 `designSystem` 配置
263
+
264
+ `designSystem` 是 Module Tools 中废弃的配置项。
265
+
266
+ 从 Module Tools vMAJOR_VERSION.33.0 版本开始,你可以使用 Tailwind CSS 的 `theme` 配置项来代替 `designSystem`,不再需要将 `theme` 配置拆分并设置到 `designSystem` 上。
267
+
268
+ - 旧版本用法:
269
+
270
+ ```ts title="modern.config.ts"
271
+ const { theme, ...rest } = tailwindConfig;
272
+
273
+ export default {
274
+ style: {
275
+ tailwindcss: rest,
276
+ },
277
+ designSystem: theme,
278
+ };
279
+ ```
280
+
281
+ - 当前版本用法:
282
+
283
+ ```ts title="modern.config.ts"
284
+ export default {
285
+ style: {
286
+ tailwindcss: tailwindConfig,
287
+ },
288
+ };
289
+ ```
@@ -63,7 +63,6 @@ const useResolvedConfigContext: () => NormalizedConfig;
63
63
  interface NormalizedConfig {
64
64
  buildConfig: PartialBuildConfig;
65
65
  buildPreset: BuildPreset;
66
- designSystem?: Record<string, any>;
67
66
  dev: Dev;
68
67
  plugins: PluginConfig;
69
68
  runtime: RuntimeConfig;
package/package.json CHANGED
@@ -9,17 +9,18 @@
9
9
  "directory": "packages/document/module-doc"
10
10
  },
11
11
  "license": "MIT",
12
- "version": "2.32.1",
12
+ "version": "2.33.0",
13
13
  "main": "index.js",
14
14
  "dependencies": {
15
15
  "react": "^18.2.0",
16
16
  "react-dom": "^18.2.0",
17
- "@modern-js/doc-tools": "2.32.1",
18
- "@modern-js/doc-plugin-auto-sidebar": "2.32.1"
17
+ "rspress": "0.0.6",
18
+ "@rspress/shared": "0.0.6",
19
+ "@modern-js/doc-plugin-auto-sidebar": "2.33.0"
19
20
  },
20
21
  "scripts": {
21
- "dev": "modern dev",
22
- "build:doc": "modern build",
23
- "preview": "modern preview"
22
+ "dev": "rspress dev",
23
+ "build:doc": "rspress build",
24
+ "preview": "rspress preview"
24
25
  }
25
26
  }
@@ -0,0 +1,130 @@
1
+ import path from 'path';
2
+ import { NavItem } from '@rspress/shared';
3
+ import { defineConfig } from 'rspress/config';
4
+ import { pluginAutoSidebar } from '@modern-js/doc-plugin-auto-sidebar';
5
+
6
+ const { version } = require('./package.json');
7
+
8
+ function getI18nHelper(lang: 'zh' | 'en') {
9
+ const cn = lang === 'zh';
10
+ const prefix = cn ? '' : '/en';
11
+ const getLink = (str: string) => `${prefix}${str}`;
12
+ const getText = (cnText: string, enText: string) => (cn ? cnText : enText);
13
+ return { getText, getLink };
14
+ }
15
+
16
+ function getNavbar(lang: 'zh' | 'en'): NavItem[] {
17
+ const { getLink, getText } = getI18nHelper(lang);
18
+
19
+ return [
20
+ {
21
+ text: getText('指南', 'Guide'),
22
+ link: getLink('/guide/intro/welcome'),
23
+ activeMatch: '^/guide/',
24
+ },
25
+ {
26
+ text: getText('API', 'API'),
27
+ link: getLink('/api/'),
28
+ activeMatch: '^/api/',
29
+ },
30
+ {
31
+ text: getText('插件', 'Plugins'),
32
+ link: getLink('/plugins/guide/getting-started'),
33
+ activeMatch: '^/plugins/',
34
+ },
35
+ {
36
+ text: `v${version}`,
37
+ items: [
38
+ {
39
+ text: getText('更新日志', 'Changelog'),
40
+ link: 'https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/module-tools/CHANGELOG.md',
41
+ },
42
+ {
43
+ text: getText('贡献指南', 'Contributing'),
44
+ link: 'https://modernjs.dev/en/community/contributing-guide.html',
45
+ },
46
+ ],
47
+ },
48
+ ];
49
+ }
50
+
51
+ export default defineConfig({
52
+ root: path.join(__dirname, 'docs'),
53
+ lang: 'zh',
54
+ base: '/module-tools/',
55
+ title: 'Module Tools',
56
+ icon: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/logo-1x-0104.png',
57
+ // The plugins for doc tools.
58
+ plugins: [
59
+ pluginAutoSidebar({
60
+ root: path.join(__dirname, 'docs'),
61
+ categories: ['zh', 'en']
62
+ .map(lang =>
63
+ ['guide', 'api', 'plugins'].map(category => `${lang}/${category}`),
64
+ )
65
+ .flat(),
66
+ collapsed: false,
67
+ }),
68
+ ],
69
+ markdown: {
70
+ checkDeadLinks: true,
71
+ experimentalMdxRs: true,
72
+ },
73
+ themeConfig: {
74
+ footer: {
75
+ message: 'Copyright © 2023 ByteDance.',
76
+ },
77
+ socialLinks: [
78
+ {
79
+ icon: 'github',
80
+ mode: 'link',
81
+ content:
82
+ 'https://github.com/web-infra-dev/modern.js/tree/main/packages/solutions/module-tools',
83
+ },
84
+ ],
85
+ locales: [
86
+ {
87
+ lang: 'zh',
88
+ label: '简体中文',
89
+ nav: getNavbar('zh'),
90
+ title: 'Module Tools',
91
+ outlineTitle: '目录',
92
+ prevPageText: '上一页',
93
+ nextPageText: '下一页',
94
+ description: '模块工程解决方案',
95
+ },
96
+ {
97
+ lang: 'en',
98
+ label: 'English',
99
+ nav: getNavbar('en'),
100
+ title: 'Module Tools',
101
+ description: 'Module Engineering Solutions',
102
+ },
103
+ ],
104
+ editLink: {
105
+ docRepoBaseUrl:
106
+ 'https://github.com/web-infra-dev/modern.js/tree/main/packages/document/module-doc/docs',
107
+ text: 'Edit this page on GitHub',
108
+ },
109
+ },
110
+ replaceRules: [
111
+ {
112
+ // The major version is different inside the ByteDance,
113
+ // so we use a flag to define it.
114
+ search: /MAJOR_VERSION/g,
115
+ replace: '2',
116
+ },
117
+ ],
118
+ builderConfig: {
119
+ dev: {
120
+ startUrl: 'http://localhost:<port>/module-tools/',
121
+ },
122
+ source: {
123
+ alias: {
124
+ '@site-docs': path.join(__dirname, './docs/zh'),
125
+ '@site-docs-en': path.join(__dirname, './docs/en'),
126
+ '@site': require('path').resolve(__dirname),
127
+ },
128
+ },
129
+ },
130
+ });
package/theme/index.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from '@modern-js/doc-tools/theme';
2
- export { default } from '@modern-js/doc-tools/theme';
1
+ // eslint-disable-next-line import/export
2
+ export * from 'rspress/theme';
3
+ export { default } from 'rspress/theme';
package/tsconfig.json CHANGED
@@ -3,5 +3,5 @@
3
3
  "compilerOptions": {
4
4
  "jsx": "preserve"
5
5
  },
6
- "include": ["./theme", "./modern.config.ts"]
6
+ "include": ["./theme", "./rspress.config.ts"]
7
7
  }