@modern-js/module-tools-docs 2.30.0 → 2.31.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 (53) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/docs/en/api/config/build-config.mdx +49 -49
  3. package/docs/en/api/config/build-preset.mdx +15 -33
  4. package/docs/en/api/config/design-system.md +42 -34
  5. package/docs/en/api/config/plugins.md +3 -3
  6. package/docs/en/api/config/testing.md +2 -2
  7. package/docs/en/api/plugin-api/plugin-hooks.md +24 -24
  8. package/docs/en/components/register-esbuild-plugin.mdx +2 -2
  9. package/docs/en/guide/advance/asset.mdx +8 -27
  10. package/docs/en/guide/advance/build-umd.mdx +18 -66
  11. package/docs/en/guide/advance/external-dependency.mdx +7 -27
  12. package/docs/en/guide/advance/in-depth-about-build.md +4 -4
  13. package/docs/en/guide/advance/in-depth-about-dev-command.md +2 -2
  14. package/docs/en/guide/advance/theme-config.mdx +4 -8
  15. package/docs/en/guide/basic/before-getting-started.md +1 -1
  16. package/docs/en/guide/basic/publish-your-project.md +8 -7
  17. package/docs/en/guide/basic/test-your-project.mdx +10 -47
  18. package/docs/en/guide/basic/use-micro-generator.md +4 -4
  19. package/docs/en/guide/basic/using-storybook.mdx +12 -44
  20. package/docs/en/guide/best-practices/components.mdx +44 -402
  21. package/docs/en/guide/faq/build.mdx +16 -0
  22. package/docs/en/guide/intro/getting-started.md +2 -2
  23. package/docs/en/plugins/guide/getting-started.mdx +8 -24
  24. package/docs/en/plugins/guide/plugin-object.mdx +2 -8
  25. package/docs/en/plugins/official-list/plugin-import.mdx +9 -52
  26. package/docs/en/plugins/official-list/plugin-node-polyfill.md +2 -2
  27. package/docs/zh/api/config/build-config.mdx +52 -52
  28. package/docs/zh/api/config/build-preset.mdx +12 -30
  29. package/docs/zh/api/config/design-system.md +6 -6
  30. package/docs/zh/api/config/plugins.md +3 -3
  31. package/docs/zh/api/config/testing.md +2 -2
  32. package/docs/zh/components/register-esbuild-plugin.mdx +2 -2
  33. package/docs/zh/guide/advance/asset.mdx +9 -30
  34. package/docs/zh/guide/advance/build-umd.mdx +19 -67
  35. package/docs/zh/guide/advance/external-dependency.mdx +8 -28
  36. package/docs/zh/guide/advance/in-depth-about-build.md +4 -4
  37. package/docs/zh/guide/advance/in-depth-about-dev-command.md +2 -2
  38. package/docs/zh/guide/advance/theme-config.mdx +4 -8
  39. package/docs/zh/guide/basic/publish-your-project.md +2 -2
  40. package/docs/zh/guide/basic/test-your-project.mdx +11 -49
  41. package/docs/zh/guide/basic/use-micro-generator.md +4 -4
  42. package/docs/zh/guide/basic/using-storybook.mdx +13 -45
  43. package/docs/zh/guide/best-practices/components.mdx +50 -410
  44. package/docs/zh/guide/faq/build.mdx +16 -0
  45. package/docs/zh/guide/intro/getting-started.md +1 -1
  46. package/docs/zh/plugins/guide/getting-started.mdx +8 -24
  47. package/docs/zh/plugins/guide/plugin-object.mdx +2 -8
  48. package/docs/zh/plugins/official-list/plugin-import.mdx +10 -55
  49. package/docs/zh/plugins/official-list/plugin-node-polyfill.md +2 -2
  50. package/modern.config.ts +1 -12
  51. package/package.json +3 -5
  52. package/theme/index.ts +0 -2
  53. package/theme/index.css +0 -9
@@ -8,9 +8,9 @@ sidebar_position: 1
8
8
 
9
9
  ## 初始化项目
10
10
 
11
- <CH.Spotlight>
11
+ 1. 推荐使用 `@modern-js/create` 命令来初始化一个 npm 项目。
12
12
 
13
- ```bash 交互式问题
13
+ ```text title="交互式问题"
14
14
  npx @modern-js/create@latest components-project
15
15
 
16
16
  ? 请选择你想创建的工程类型:Npm 模块
@@ -19,24 +19,9 @@ npx @modern-js/create@latest components-project
19
19
  ? 请选择包管理工具:pnpm
20
20
  ```
21
21
 
22
- ---
23
-
24
- 推荐使用 `@modern-js/create` 命令来初始化一个 npm 项目。
25
-
26
- ```bash 交互式问题
27
- npx @modern-js/create@latest components-project
28
-
29
- ? 请选择你想创建的工程类型:Npm 模块
30
- ? 请填写项目名称:components-demo
31
- ? 请选择开发语言:TS
32
- ? 请选择包管理工具:pnpm
33
- ```
22
+ 2. 初始化的目录结构如下:
34
23
 
35
- ---
36
-
37
- 初始化的目录结构。
38
-
39
- ```bash 初始化的目录结构。
24
+ ```bash
40
25
  .
41
26
  ├── README.md
42
27
  ├── node_modules/
@@ -50,149 +35,17 @@ npx @modern-js/create@latest components-project
50
35
  └── tsconfig.json
51
36
  ```
52
37
 
53
- ---
54
-
55
- 修改 `./src/index.ts` 文件后缀和内容。
38
+ 3. 最后修改 `./src/index.ts` 文件后缀和内容如下,就完成了组件项目的初始化。
56
39
 
57
- 此时就初始化了一个组件项目。
58
-
59
- ```tsx ./src/index.tsx
40
+ ```tsx title="./src/index.tsx"
60
41
  export default () => {
61
42
  return <div>hello world</div>;
62
43
  };
63
44
  ```
64
45
 
65
- </CH.Spotlight>
66
-
67
46
  ## 使用 Storybook 调试代码
68
47
 
69
- <CH.Spotlight>
70
-
71
- ```bash 终端
72
- pnpm run new
73
-
74
- ? 请选择你想要的操作 启用可选功能
75
- ? 请选择功能名称 启用「Storybook」
76
- ```
77
-
78
- ---
79
-
80
- 在项目根目录下执行 `new` 命令,可以开启 Storybook 功能。
81
-
82
- ```bash 终端
83
- pnpm run new
84
-
85
- ? 请选择你想要的操作 启用可选功能
86
- ? 请选择功能名称 启用「Storybook」
87
- ```
88
-
89
- ---
90
-
91
- 成功开启后,会看到 `package.json` 中新增了依赖。同时创建了 `stories` 目录和相关的初始化文件。
92
-
93
- <CH.Code>
94
-
95
- ```json ./package.json focus=4:7
96
- {
97
- "name": "components-demo",
98
- "devDependencies": {
99
- "@modern-js/plugin-storybook": "x.y.z",
100
- "@modern-js/runtime": "x.y.z",
101
- "react": "^17",
102
- "react-dom": "^17"
103
- }
104
- }
105
- ```
106
-
107
- ```bash 目录结构
108
- .
109
- ├── src
110
- │ ├── index.ts
111
- │ └── modern-app-env.d.ts
112
- ├── stories
113
- │ ├── .eslintrc.js
114
- │ ├── index.stories.tsx
115
- │ └── tsconfig.json
116
- ```
117
-
118
- </CH.Code>
119
-
120
- ---
121
-
122
- 初始化后,在 `./stories` 目录下的 `tsconfig.json` 文件中默认设置了与项目同名的 `paths` 配置。
123
-
124
- ```json ./stories/tsconfig.json focus=5:7
125
- {
126
- "extends": "../tsconfig.json",
127
- "compilerOptions": {
128
- "baseUrl": "../",
129
- "paths": {
130
- "components-demo": ["./"],
131
- "components-demo/*": ["./*"]
132
- }
133
- },
134
- "include": ["**/*"]
135
- }
136
- ```
137
-
138
- ---
139
-
140
- 这样的配置可以让你在 Story 代码中直接使用项目的名称引入代码。
141
-
142
- <CH.Code>
143
-
144
- ```tsx ./stories/index.stories.tsx
145
- import Component from 'components-demo';
146
-
147
- export const YourStory = () => <Component />;
148
-
149
- export default {
150
- title: 'Your Stories',
151
- };
152
- ```
153
-
154
- ---
155
-
156
- ```tsx ./src/index.tsx
157
- export default () => {
158
- return <div>hello world</div>;
159
- };
160
- ```
161
-
162
- </CH.Code>
163
-
164
- ---
165
-
166
- 此时 Storybook 会根据项目的 `package.json` 文件中的 `main`、`exports` 这样的字段确认导入代码的入口;
167
- 根据 `types` 字段确定类型文件的位置。
168
-
169
- ```json package.json
170
- {
171
- "name": "components-demo",
172
- "main": "./dist/esm/index.js",
173
- "types": "./dist/types/index.d.ts"
174
- }
175
- ```
176
-
177
- ---
178
-
179
- 虽然也支持导入源代码进行调试,不过使用项目产物调试更加可靠。
180
-
181
- 使用源代码调试存在局限性:某些配置无法在 Storybook 和原本构建支持的配置等价使用。
182
-
183
- **因此更推荐使用产物进行调试**。
184
-
185
- ```tsx ./stories/index.stories.tsx
186
- import Component from '../src';
187
-
188
- export const YourStory = () => <Component />;
189
-
190
- export default {
191
- title: 'Your Stories',
192
- };
193
- ```
194
-
195
- </CH.Spotlight>
48
+ 请参考 [「使用 Storybook」](/guide/basic/using-storybook.html) 来使用 Storybook 调试代码。
196
49
 
197
50
  ## 开发样式
198
51
 
@@ -220,9 +73,9 @@ export default {
220
73
 
221
74
  因此我们可以在项目中创建 `.css` 文件,并且可以直接在 css 文件中使用这些插件提供的语法支持和能力。
222
75
 
223
- <CH.Spotlight>
76
+ - 源代码:
224
77
 
225
- ```css ./src/index.css
78
+ ```less title="./src/index.css"
226
79
  a,
227
80
  b {
228
81
  color: red;
@@ -240,19 +93,9 @@ b {
240
93
  }
241
94
  ```
242
95
 
243
- ---
244
-
245
- 源代码。
246
-
247
- ```css ./src/index.css
248
-
249
- ```
250
-
251
- ---
252
-
253
- css 产物。
96
+ - CSS 产物:
254
97
 
255
- ```css ./dist/es/index.css
98
+ ```css title="./dist/es/index.css"
256
99
  a,
257
100
  b {
258
101
  color: red;
@@ -269,17 +112,15 @@ e b {
269
112
  }
270
113
  ```
271
114
 
272
- </CH.Spotlight>
273
-
274
115
  ### Less
275
116
 
276
117
  模块工程支持使用 Less 开发样式。
277
118
 
278
119
  > 目前内置的 Less 版本为 v4.1.3
279
120
 
280
- <CH.Spotlight>
121
+ - 源代码:
281
122
 
282
- ```less ./src/common.less
123
+ ```less title="./src/common.less"
283
124
  @bg: black;
284
125
  @bg-light: boolean(luma(@bg) > 50%);
285
126
 
@@ -289,36 +130,24 @@ div {
289
130
  }
290
131
  ```
291
132
 
292
- ---
293
-
294
- 源代码。
295
-
296
- ```less ./src/common.less
297
-
298
- ```
299
-
300
- ---
301
-
302
- Less 产物。
133
+ - Less 产物:
303
134
 
304
- ```css ./dist/es/common.css
135
+ ```css title="./dist/es/common.css"
305
136
  div {
306
137
  background: black;
307
138
  color: white;
308
139
  }
309
140
  ```
310
141
 
311
- </CH.Spotlight>
312
-
313
142
  ### Sass/Scss
314
143
 
315
144
  模块工程支持使用 Scss/Sass 开发样式。
316
145
 
317
146
  > 目前内置的 Sass 版本为 v1.54.4
318
147
 
319
- <CH.Spotlight>
148
+ - 源代码:
320
149
 
321
- ```sass ./src/common.sass
150
+ ```scss title="./src/common.sass"
322
151
  $font-stack: Helvetica, sans-serif;
323
152
  $primary-color: #333;
324
153
 
@@ -328,58 +157,33 @@ body {
328
157
  }
329
158
  ```
330
159
 
331
- ---
332
-
333
- 源代码。
334
-
335
- ```sass ./src/common.sass
336
-
337
- ```
338
-
339
- ---
340
-
341
- Less 产物。
160
+ - Sass 产物:
342
161
 
343
- ```css ./dist/es/common.css
162
+ ```css title="./dist/es/common.css"
344
163
  body {
345
164
  font: 100% Helvetica, sans-serif;
346
165
  color: #333;
347
166
  }
348
167
  ```
349
168
 
350
- </CH.Spotlight>
351
-
352
169
  ### Tailwind CSS
353
170
 
354
171
  模块工程支持使用 Tailwind CSS 开发组件样式。
355
172
 
356
173
  默认情况下,模块工程没有开启该功能,需要按照下面的方式开启它。
357
174
 
358
- <CH.Spotlight>
175
+ 1. 在项目根目录下执行 `new` 命令,可以开启 Tailwind CSS 功能。
359
176
 
360
- ```bash 终端
361
- pnpm run new
362
-
363
- ? 请选择你想要的操作 启用可选功能
364
- ? 请选择功能名称 启用「Storybook」
365
- ```
366
-
367
- ---
368
-
369
- 在项目根目录下执行 `new` 命令,可以开启 Tailwind CSS 功能。
370
-
371
- ```bash 终端
177
+ ```text title="终端"
372
178
  pnpm run new
373
179
 
374
180
  ? 请选择你想要的操作 启用可选功能
375
181
  ? 请选择功能名称 启用 「Tailwind CSS」 支持
376
182
  ```
377
183
 
378
- ---
184
+ 2. 成功开启后,会看到 `package.json` 中新增了依赖。
379
185
 
380
- 成功开启后,会看到 `package.json` 中新增了依赖。
381
-
382
- ```json ./package.json
186
+ ```json title="./package.json"
383
187
  {
384
188
  "devDependencies": {
385
189
  "@modern-js/plugin-tailwindcss": "x.y.z"
@@ -387,15 +191,13 @@ pnpm run new
387
191
  }
388
192
  ```
389
193
 
390
- </CH.Spotlight>
391
-
392
- Tailwind CSS 提供了两种使用方式:
194
+ 3. Tailwind CSS 提供了两种使用方式:
393
195
 
394
196
  #### HTML 类名
395
197
 
396
- <CH.Spotlight>
198
+ Tailwind CSS 支持在 HTML 标签上使用类名的方式增加样式。**当使用 HTML 类名的时候,一定要注意导入 Tailwind CSS 相应的 css 文件。**
397
199
 
398
- ```tsx ./src/index.tsx
200
+ ```tsx title="./src/index.tsx"
399
201
  import 'tailwindcss/utilities.css';
400
202
 
401
203
  export default () => {
@@ -403,61 +205,13 @@ export default () => {
403
205
  };
404
206
  ```
405
207
 
406
- ---
407
-
408
- Tailwind CSS 支持在 HTML 标签上使用类名的方式增加样式。
409
-
410
- ```tsx ./src/index.tsx focus=5:5
208
+ 样式产物(此时是 bundle 构建):
411
209
 
412
- ```
413
-
414
- ---
415
-
416
- **当使用 HTML 类名的时候,一定要注意导入 Tailwind CSS 相应的 css 文件。**
417
-
418
- ```tsx ./src/index.tsx focus=1:1
419
-
420
- ```
421
-
422
- ---
423
-
424
- 样式产物。
425
-
426
- > 此时是 bundle 构建。
427
-
428
- ```css ./dist/es/index.css
429
- /* ../../node_modules/.pnpm/tailwindcss@2.2.19/node_modules/tailwindcss/utilities.css */
210
+ ```css title="./dist/es/index.css"
211
+ /* node_modules/tailwindcss/utilities.css */
430
212
  .table {
431
213
  display: table;
432
214
  }
433
- @keyframes spin {
434
- to {
435
- transform: rotate(360deg);
436
- }
437
- }
438
- @keyframes ping {
439
- 75%,
440
- 100% {
441
- transform: scale(2);
442
- opacity: 0;
443
- }
444
- }
445
- @keyframes pulse {
446
- 50% {
447
- opacity: 0.5;
448
- }
449
- }
450
- @keyframes bounce {
451
- 0%,
452
- 100% {
453
- transform: translateY(-25%);
454
- animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
455
- }
456
- 50% {
457
- transform: none;
458
- animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
459
- }
460
- }
461
215
  .bg-black {
462
216
  --tw-bg-opacity: 1;
463
217
  background-color: rgba(0, 0, 0, var(--tw-bg-opacity));
@@ -466,35 +220,9 @@ Tailwind CSS 支持在 HTML 标签上使用类名的方式增加样式。
466
220
  --tw-text-opacity: 1;
467
221
  color: rgba(255, 255, 255, var(--tw-text-opacity));
468
222
  }
469
- *,
470
- ::before,
471
- ::after {
472
- --tw-shadow: 0 0 #0000;
473
- }
474
- *,
475
- ::before,
476
- ::after {
477
- --tw-ring-inset: var(--tw-empty);
478
- --tw-ring-offset-width: 0px;
479
- --tw-ring-offset-color: #fff;
480
- --tw-ring-color: rgba(59, 130, 246, 0.5);
481
- --tw-ring-offset-shadow: 0 0 #0000;
482
- --tw-ring-shadow: 0 0 #0000;
483
- }
484
- @media (min-width: 640px) {
485
- }
486
- @media (min-width: 768px) {
487
- }
488
- @media (min-width: 1024px) {
489
- }
490
- @media (min-width: 1280px) {
491
- }
492
- @media (min-width: 1536px) {
493
- }
223
+ /** some more... */
494
224
  ```
495
225
 
496
- </CH.Spotlight>
497
-
498
226
  #### `@apply`
499
227
 
500
228
  Tailwind CSS 提供了 [`@apply`](https://v2.tailwindcss.com/docs/functions-and-directives#apply) 指令,可以通过它将 Tailwind CSS 提供的样式内联到我们编写的样式中。
@@ -513,7 +241,7 @@ Tailwind CSS 提供了 [`@apply`](https://v2.tailwindcss.com/docs/functions-and-
513
241
 
514
242
  当将 Tailwind 与 Sass 一起使用时,`@apply` 后面存在 `!important` 的时候,需要使用插值来让 Sass 正确编译。
515
243
 
516
- <CH.Spotlight>
244
+ - 不能正常工作:
517
245
 
518
246
  ```sass
519
247
  .alert {
@@ -521,17 +249,7 @@ Tailwind CSS 提供了 [`@apply`](https://v2.tailwindcss.com/docs/functions-and-
521
249
  }
522
250
  ```
523
251
 
524
- ---
525
-
526
- 不能正常工作。
527
-
528
- ```sass
529
-
530
- ```
531
-
532
- ---
533
-
534
- 能够正常工作。
252
+ - 能够正常工作:
535
253
 
536
254
  ```sass
537
255
  .alert {
@@ -539,13 +257,11 @@ Tailwind CSS 提供了 [`@apply`](https://v2.tailwindcss.com/docs/functions-and-
539
257
  }
540
258
  ```
541
259
 
542
- </CH.Spotlight>
543
-
544
260
  ##### Less
545
261
 
546
262
  在与 Less 一起使用 Tailwind 时,你不能嵌套 Tailwind 的 `@screen` 指令。
547
263
 
548
- <CH.Spotlight>
264
+ - 不能正常工作:
549
265
 
550
266
  ```less
551
267
  .card {
@@ -557,21 +273,9 @@ Tailwind CSS 提供了 [`@apply`](https://v2.tailwindcss.com/docs/functions-and-
557
273
  }
558
274
  ```
559
275
 
560
- ---
561
-
562
- 不能正常工作。
563
-
564
- ```less
565
-
566
- ```
567
-
568
- ---
276
+ - 相反,使用常规的媒体查询和 `theme()` 函数来引用你的屏幕尺寸,或者干脆不要嵌套你的 `@screen` 指令。
569
277
 
570
- 相反,使用常规的媒体查询和 `theme()` 函数来引用你的屏幕尺寸,或者干脆不要嵌套你的 `@screen` 指令。
571
-
572
- <CH.Code>
573
-
574
- ```less 方法一
278
+ ```less title="方法一"
575
279
  // Use a regular media query and theme()
576
280
  .card {
577
281
  @apply rounded-none;
@@ -582,9 +286,7 @@ Tailwind CSS 提供了 [`@apply`](https://v2.tailwindcss.com/docs/functions-and-
582
286
  }
583
287
  ```
584
288
 
585
- ---
586
-
587
- ```less 方法二
289
+ ```less title="方法二"
588
290
  // Use the @screen directive at the top-level
589
291
  .card {
590
292
  @apply rounded-none;
@@ -595,10 +297,6 @@ Tailwind CSS 提供了 [`@apply`](https://v2.tailwindcss.com/docs/functions-and-
595
297
  }
596
298
  ```
597
299
 
598
- </CH.Code>
599
-
600
- </CH.Spotlight>
601
-
602
300
  #### 推荐方式
603
301
 
604
302
  **推荐使用 `@apply` 指定的方式开发样式,这样在样式产物中仅包含通过指令内联的样式。**
@@ -611,7 +309,7 @@ Tailwind CSS 提供了 [`@apply`](https://v2.tailwindcss.com/docs/functions-and-
611
309
 
612
310
  > 所谓 bundle 和 bundleless 可以查看 [「Bundle 和 Bundleless」](/guide/advance/in-depth-about-build#bundle-和-bundleless)
613
311
 
614
- ```tsx ./src/index.tsx
312
+ ```tsx title="./src/index.tsx"
615
313
  import 'tailwindcss/utilities.css';
616
314
 
617
315
  export default () => {
@@ -625,38 +323,11 @@ Bundle 模式下,会将第三方依赖打包进来。
625
323
 
626
324
  如果需要将样式注入 JS 产物中,可以开启 [`style.inject`](/api/config/build-config#styleinject) 选项。
627
325
 
628
- <CH.Code>
629
- ```css ./dist/es/index.css
630
- /* ../../node_modules/.pnpm/tailwindcss@2.2.19/node_modules/tailwindcss/utilities.css */
326
+ ```css title="./dist/es/index.css"
327
+ /* node_modules/tailwindcss/utilities.css */
631
328
  .table {
632
329
  display: table;
633
330
  }
634
- @keyframes spin {
635
- to {
636
- transform: rotate(360deg);
637
- }
638
- }
639
- @keyframes ping {
640
- 75%, 100% {
641
- transform: scale(2);
642
- opacity: 0;
643
- }
644
- }
645
- @keyframes pulse {
646
- 50% {
647
- opacity: .5;
648
- }
649
- }
650
- @keyframes bounce {
651
- 0%, 100% {
652
- transform: translateY(-25%);
653
- animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
654
- }
655
- 50% {
656
- transform: none;
657
- animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
658
- }
659
- }
660
331
  .bg-black {
661
332
  --tw-bg-opacity: 1;
662
333
  background-color: rgba(0, 0, 0, var(--tw-bg-opacity));
@@ -665,51 +336,24 @@ Bundle 模式下,会将第三方依赖打包进来。
665
336
  --tw-text-opacity: 1;
666
337
  color: rgba(255, 255, 255, var(--tw-text-opacity));
667
338
  }
668
- *,
669
- ::before,
670
- ::after {
671
- --tw-shadow: 0 0 #0000 ;
672
- }
673
- *,
674
- ::before,
675
- ::after {
676
- --tw-ring-inset: var(--tw-empty, );
677
- --tw-ring-offset-width: 0px;
678
- --tw-ring-offset-color: #fff;
679
- --tw-ring-color: rgba(59, 130, 246, 0.5);
680
- --tw-ring-offset-shadow: 0 0 #0000;
681
- --tw-ring-shadow: 0 0 #0000 ;
682
- }
683
- @media (min-width: 640px) {
684
- }
685
- @media (min-width: 768px) {
686
- }
687
- @media (min-width: 1024px) {
688
- }
689
- @media (min-width: 1280px) {
690
- }
691
- @media (min-width: 1536px) {
692
- }
339
+ /** some more... */
693
340
  ```
694
- ---
695
- ``` js ./dist/es/index.js
341
+
342
+ ```js title="./dist/es/index.js"
696
343
  // src/index.tsx
697
- import { jsx } from "react/jsx-runtime";
344
+ import { jsx } from 'react/jsx-runtime';
698
345
  var src_default = () => {
699
- return /* @__PURE__ */ jsx("div", {
700
- className: "bg-black text-white",
701
- children: "hello world11"
346
+ return /* @__PURE__ */ jsx('div', {
347
+ className: 'bg-black text-white',
348
+ children: 'hello world11',
702
349
  });
703
350
  };
704
- export {
705
- src_default as default
706
- };
351
+ export { src_default as default };
707
352
  ```
708
- </CH.Code>
709
353
 
710
354
  Bundleless 模式下,并不会将第三方依赖打包进来,此时不会有样式产物生成。
711
355
 
712
- ```js ./dist/es/index.js
356
+ ```js title="./dist/es/index.js"
713
357
  import { jsx } from 'react/jsx-runtime';
714
358
  import 'tailwindcss/utilities.css';
715
359
  var src_default = () => {
@@ -737,9 +381,7 @@ export { src_default as default };
737
381
 
738
382
  下面是一个代码示例:
739
383
 
740
- <CH.Code>
741
-
742
- ```tsx ./src/index.tsx
384
+ ```tsx title="./src/index.tsx"
743
385
  import style from './index.module.css';
744
386
 
745
387
  export default () => {
@@ -747,14 +389,12 @@ export default () => {
747
389
  };
748
390
  ```
749
391
 
750
- ```css ./src/index.module.css
392
+ ```css title="./src/index.module.css"
751
393
  .btn {
752
394
  color: blue;
753
395
  }
754
396
  ```
755
397
 
756
- </CH.Code>
757
-
758
398
  ## 配置构建产物
759
399
 
760
400
  根据组件项目使用的多数场景,**推荐使用 `npm-component` 构建预设**。该预设得到的产物目录结构为:
@@ -234,3 +234,19 @@ import RegisterEsbuildPlugin from '@site-docs/components/register-esbuild-plugin
234
234
 
235
235
  - 方案一:[typed-css-modules](https://github.com/Quramy/typed-css-modules)
236
236
  - 方案二:[postcss-modules-dts](https://www.npmjs.com/package/@guanghechen/postcss-modules-dts)
237
+
238
+ ```ts title="modern.config.ts"
239
+ import { defineConfig } from '@modern-js/module-tools';
240
+
241
+ export default defineConfig(async () => {
242
+ const { dts } = await import("@guanghechen/postcss-modules-dts");
243
+ return {
244
+ buildConfig: {
245
+ style: {
246
+ modules: { ...dts },
247
+ },
248
+ },
249
+ // 你的自定义配置
250
+ }
251
+ });
252
+ ```
@@ -81,7 +81,7 @@ export default defineConfig({
81
81
 
82
82
  `@modern-js/module-tools` 是基于 Modern.js 的插件体系实现的,本质上是一个插件,因此你需要在配置文件的 `plugins` 字段中注册 `moduleTools`:
83
83
 
84
- ```ts modern.config.ts
84
+ ```ts title="modern.config.ts"
85
85
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
86
86
 
87
87
  export default defineConfig({