@modern-js/module-tools-docs 2.0.0-beta.4

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 (163) hide show
  1. package/LICENSE +144 -0
  2. package/docs/.island/config.ts +245 -0
  3. package/docs/.island/dist/404.html +41 -0
  4. package/docs/.island/dist/assets/before-getting-started.1b82b538.js +87 -0
  5. package/docs/.island/dist/assets/before-getting-started.582a31cc.js +87 -0
  6. package/docs/.island/dist/assets/build-config.72eb0918.js +804 -0
  7. package/docs/.island/dist/assets/build-config.d8bb1658.js +809 -0
  8. package/docs/.island/dist/assets/build-preset.96805d7d.js +256 -0
  9. package/docs/.island/dist/assets/build-preset.c20dcd40.js +256 -0
  10. package/docs/.island/dist/assets/build-your-ui.7f349247.js +2 -0
  11. package/docs/.island/dist/assets/build-your-ui.a8361604.js +2 -0
  12. package/docs/.island/dist/assets/command-preview.2d45fc82.js +264 -0
  13. package/docs/.island/dist/assets/command-preview.dc51b953.js +264 -0
  14. package/docs/.island/dist/assets/components.esm.03560353.js +9 -0
  15. package/docs/.island/dist/assets/design-system.86694ff5.js +1254 -0
  16. package/docs/.island/dist/assets/design-system.c4745cce.js +639 -0
  17. package/docs/.island/dist/assets/dev.1d326a37.js +37 -0
  18. package/docs/.island/dist/assets/dev.1fd06000.js +37 -0
  19. package/docs/.island/dist/assets/down.f35427d3.svg +1 -0
  20. package/docs/.island/dist/assets/extension.12299fd6.js +2 -0
  21. package/docs/.island/dist/assets/extension.96dc63a4.js +2 -0
  22. package/docs/.island/dist/assets/getting-started.40e9218d.js +117 -0
  23. package/docs/.island/dist/assets/getting-started.b1ed3f10.js +114 -0
  24. package/docs/.island/dist/assets/github.3bf8ccee.svg +1 -0
  25. package/docs/.island/dist/assets/index.2b2347ea.js +33 -0
  26. package/docs/.island/dist/assets/index.6cef6f5f.js +4 -0
  27. package/docs/.island/dist/assets/index.cb118238.js +36 -0
  28. package/docs/.island/dist/assets/index.ccb6ce27.js +4 -0
  29. package/docs/.island/dist/assets/island_inject.11a12ecc.js +1 -0
  30. package/docs/.island/dist/assets/island_inject.b13deaee.js +1 -0
  31. package/docs/.island/dist/assets/loading.8c9bb911.svg +1 -0
  32. package/docs/.island/dist/assets/modify-output-product.7f6bff35.js +100 -0
  33. package/docs/.island/dist/assets/modify-output-product.b91eff1f.js +100 -0
  34. package/docs/.island/dist/assets/moon.6b705924.svg +3 -0
  35. package/docs/.island/dist/assets/plugin.895932d8.js +42 -0
  36. package/docs/.island/dist/assets/plugin.d2fbc531.js +42 -0
  37. package/docs/.island/dist/assets/publish-your-project.21b8309f.js +164 -0
  38. package/docs/.island/dist/assets/publish-your-project.8d398b17.js +166 -0
  39. package/docs/.island/dist/assets/right.89674cd7.svg +1 -0
  40. package/docs/.island/dist/assets/search.0aea6901.svg +1 -0
  41. package/docs/.island/dist/assets/search.1c85d17c.js +3 -0
  42. package/docs/.island/dist/assets/search.484eca11.js +222 -0
  43. package/docs/.island/dist/assets/search.54fca8d0.js +3 -0
  44. package/docs/.island/dist/assets/style.09015a4b.css +1 -0
  45. package/docs/.island/dist/assets/style.2e5f7bc2.css +1970 -0
  46. package/docs/.island/dist/assets/sun.841dac10.svg +11 -0
  47. package/docs/.island/dist/assets/test-your-project.18bd4582.js +190 -0
  48. package/docs/.island/dist/assets/test-your-project.f53bebf7.js +190 -0
  49. package/docs/.island/dist/assets/test.0da1f99f.js +67 -0
  50. package/docs/.island/dist/assets/test.0e81f002.js +66 -0
  51. package/docs/.island/dist/assets/translator.b1077c44.svg +1 -0
  52. package/docs/.island/dist/assets/use-micro-generator.7d9e4016.js +60 -0
  53. package/docs/.island/dist/assets/use-micro-generator.db5520c1.js +60 -0
  54. package/docs/.island/dist/assets/using-storybook.57ea6b77.js +260 -0
  55. package/docs/.island/dist/assets/using-storybook.a2212f2e.js +260 -0
  56. package/docs/.island/dist/assets/welcome.0449a9c8.js +13 -0
  57. package/docs/.island/dist/assets/welcome.a8448931.js +13 -0
  58. package/docs/.island/dist/assets/why-module-engineering-solution.6ae8c0e3.js +26 -0
  59. package/docs/.island/dist/assets/why-module-engineering-solution.c9a45cbd.js +26 -0
  60. package/docs/.island/dist/chunk-COLCRJ2V.js +1 -0
  61. package/docs/.island/dist/chunk-K5FMOYDC.js +10 -0
  62. package/docs/.island/dist/chunk-WE42KMYS.js +26 -0
  63. package/docs/.island/dist/client-entry.js +3 -0
  64. package/docs/.island/dist/en/api/build-config.html +344 -0
  65. package/docs/.island/dist/en/api/build-preset.html +82 -0
  66. package/docs/.island/dist/en/api/design-system.html +155 -0
  67. package/docs/.island/dist/en/api/dev.html +45 -0
  68. package/docs/.island/dist/en/api/index.html +41 -0
  69. package/docs/.island/dist/en/api/plugin.html +48 -0
  70. package/docs/.island/dist/en/api/test.html +58 -0
  71. package/docs/.island/dist/en/guide/before-getting-started.html +127 -0
  72. package/docs/.island/dist/en/guide/build-your-ui.html +41 -0
  73. package/docs/.island/dist/en/guide/command-preview.html +100 -0
  74. package/docs/.island/dist/en/guide/extension.html +41 -0
  75. package/docs/.island/dist/en/guide/getting-started.html +76 -0
  76. package/docs/.island/dist/en/guide/modify-output-product.html +140 -0
  77. package/docs/.island/dist/en/guide/publish-your-project.html +91 -0
  78. package/docs/.island/dist/en/guide/test-your-project.html +72 -0
  79. package/docs/.island/dist/en/guide/use-micro-generator.html +65 -0
  80. package/docs/.island/dist/en/guide/using-storybook.html +113 -0
  81. package/docs/.island/dist/en/guide/welcome.html +53 -0
  82. package/docs/.island/dist/en/guide/why-module-engineering-solution.html +49 -0
  83. package/docs/.island/dist/en/index.html +42 -0
  84. package/docs/.island/dist/react-dom.js +1 -0
  85. package/docs/.island/dist/react-dom_client.js +1 -0
  86. package/docs/.island/dist/react.js +1 -0
  87. package/docs/.island/dist/react_jsx-runtime.js +10 -0
  88. package/docs/.island/dist/ssr-manifest.json +57 -0
  89. package/docs/.island/dist/test-result.png +0 -0
  90. package/docs/.island/dist/why-module-solution.png +0 -0
  91. package/docs/.island/dist/zh/api/build-config.html +347 -0
  92. package/docs/.island/dist/zh/api/build-preset.html +82 -0
  93. package/docs/.island/dist/zh/api/design-system.html +149 -0
  94. package/docs/.island/dist/zh/api/dev.html +46 -0
  95. package/docs/.island/dist/zh/api/index.html +41 -0
  96. package/docs/.island/dist/zh/api/plugin.html +48 -0
  97. package/docs/.island/dist/zh/api/test.html +59 -0
  98. package/docs/.island/dist/zh/guide/before-getting-started.html +127 -0
  99. package/docs/.island/dist/zh/guide/build-your-ui.html +41 -0
  100. package/docs/.island/dist/zh/guide/command-preview.html +100 -0
  101. package/docs/.island/dist/zh/guide/extension.html +41 -0
  102. package/docs/.island/dist/zh/guide/getting-started.html +79 -0
  103. package/docs/.island/dist/zh/guide/modify-output-product.html +140 -0
  104. package/docs/.island/dist/zh/guide/publish-your-project.html +92 -0
  105. package/docs/.island/dist/zh/guide/test-your-project.html +72 -0
  106. package/docs/.island/dist/zh/guide/use-micro-generator.html +65 -0
  107. package/docs/.island/dist/zh/guide/using-storybook.html +114 -0
  108. package/docs/.island/dist/zh/guide/welcome.html +53 -0
  109. package/docs/.island/dist/zh/guide/why-module-engineering-solution.html +49 -0
  110. package/docs/.island/dist/zh/index.html +42 -0
  111. package/docs/.island/index.html +39 -0
  112. package/docs/.island/styles/index.css +10 -0
  113. package/docs/en/api/build-config.md +501 -0
  114. package/docs/en/api/build-preset.md +214 -0
  115. package/docs/en/api/design-system.md +524 -0
  116. package/docs/en/api/dev.md +32 -0
  117. package/docs/en/api/index.md +3 -0
  118. package/docs/en/api/plugin.md +34 -0
  119. package/docs/en/api/test.md +48 -0
  120. package/docs/en/guide/advance/asset.mdx +132 -0
  121. package/docs/en/guide/advance/build-umd.mdx +241 -0
  122. package/docs/en/guide/advance/copy.md +235 -0
  123. package/docs/en/guide/advance/external-dependency.mdx +125 -0
  124. package/docs/en/guide/advance/in-depth-about-build.md +266 -0
  125. package/docs/en/guide/advance/in-depth-about-dev-command.md +22 -0
  126. package/docs/en/guide/basic/before-getting-started.md +187 -0
  127. package/docs/en/guide/basic/command-preview.md +204 -0
  128. package/docs/en/guide/basic/modify-output-product.md +145 -0
  129. package/docs/en/guide/basic/publish-your-project.md +115 -0
  130. package/docs/en/guide/basic/test-your-project.mdx +158 -0
  131. package/docs/en/guide/basic/use-micro-generator.md +35 -0
  132. package/docs/en/guide/basic/using-storybook.mdx +187 -0
  133. package/docs/en/guide/intro/getting-started.md +78 -0
  134. package/docs/en/guide/intro/welcome.md +14 -0
  135. package/docs/en/guide/intro/why-module-engineering-solution.md +17 -0
  136. package/docs/en/index.md +35 -0
  137. package/docs/public/test-result.png +0 -0
  138. package/docs/public/why-module-solution.png +0 -0
  139. package/docs/zh/api/build-config.md +570 -0
  140. package/docs/zh/api/build-preset.md +220 -0
  141. package/docs/zh/api/design-system.md +1147 -0
  142. package/docs/zh/api/dev.md +33 -0
  143. package/docs/zh/api/index.md +3 -0
  144. package/docs/zh/api/plugins.md +108 -0
  145. package/docs/zh/api/testing.md +52 -0
  146. package/docs/zh/guide/advance/asset.mdx +132 -0
  147. package/docs/zh/guide/advance/build-umd.mdx +232 -0
  148. package/docs/zh/guide/advance/copy.md +235 -0
  149. package/docs/zh/guide/advance/external-dependency.mdx +125 -0
  150. package/docs/zh/guide/advance/in-depth-about-build.md +267 -0
  151. package/docs/zh/guide/advance/in-depth-about-dev-command.md +26 -0
  152. package/docs/zh/guide/basic/before-getting-started.md +187 -0
  153. package/docs/zh/guide/basic/command-preview.md +204 -0
  154. package/docs/zh/guide/basic/modify-output-product.md +144 -0
  155. package/docs/zh/guide/basic/publish-your-project.md +112 -0
  156. package/docs/zh/guide/basic/test-your-project.mdx +158 -0
  157. package/docs/zh/guide/basic/use-micro-generator.md +35 -0
  158. package/docs/zh/guide/basic/using-storybook.mdx +186 -0
  159. package/docs/zh/guide/intro/getting-started.md +78 -0
  160. package/docs/zh/guide/intro/welcome.md +14 -0
  161. package/docs/zh/guide/intro/why-module-engineering-solution.md +17 -0
  162. package/docs/zh/index.md +29 -0
  163. package/package.json +19 -0
@@ -0,0 +1,570 @@
1
+ # BuildConfig
2
+ 本章节描述了Module tools关于构建的所有配置
3
+ ## alias
4
+ - type: `Record<string, string | string[]> | Function`
5
+ - default: `{'@': 'src',}`
6
+
7
+ :::tip
8
+ 对于 TypeScript 项目,只需要在 `tsconfig.json` 中配置 [compilerOptions.paths](https://www.typescriptlang.org/tsconfig#paths), Module tools会自动识别 `tsconfig.json` 里的别名,因此不需要额外配置 `alias` 字段。
9
+ :::
10
+
11
+ ```ts modern.config.ts
12
+ import { defineConfig } from '@modern-js/module-tools';
13
+
14
+ export default defineConfig({
15
+ buildConfig: {
16
+ alias: {
17
+ '@common': './src/common',
18
+ },
19
+ },
20
+ });
21
+ ```
22
+
23
+ 以上配置完成后,如果在代码中引用 `@common/Foo.tsx`, 则会映射到 `<root>/src/common/Foo.tsx` 路径上。
24
+
25
+ `alias` 的值定义为函数时,可以接受预设的 alias 对象,并对其进行修改。
26
+
27
+ ```ts modern.config.ts
28
+ import { defineConfig } from '@modern-js/module-tools';
29
+
30
+ export default defineConfig({
31
+ buildConfig: {
32
+ alias: alias => {
33
+ alias['@common'] = './src/common';
34
+ },
35
+ },
36
+ });
37
+ ```
38
+
39
+ 也可以在函数中返回一个新对象作为最终结果,新对象会覆盖预设的 alias 对象。
40
+
41
+ ```ts modern.config.ts
42
+ import { defineConfig } from '@modern-js/module-tools';
43
+
44
+ export default defineConfig({
45
+ buildConfig: {
46
+ alias: alias => {
47
+ return {
48
+ '@common': './src/common',
49
+ };
50
+ },
51
+ },
52
+ });
53
+ ```
54
+
55
+ ## asset
56
+
57
+ ### path
58
+ 静态资源输出路径,会基于[outdir](/zh/api/build-config/#outdir)进行输出
59
+
60
+ - type: `string`
61
+ - default: `assets`
62
+
63
+ ### limit
64
+ 打包时自动内联静态资源的阈值,小于 10240 字节的资源会被自动内联进bundle产物中
65
+
66
+ - type: `number`
67
+ - default: `10 * 1024`
68
+
69
+ ### publicPath
70
+ 打包时给未内联资源的CDN前缀
71
+ - type: `string`
72
+ - default: `undefined`
73
+ ```ts modern.config.ts
74
+ import { defineConfig } from '@modern-js/module-tools';
75
+
76
+ export default defineConfig({
77
+ buildConfig: {
78
+ asset: {
79
+ publicPath: 'https://xxx/'
80
+ }
81
+ }
82
+ });
83
+ ```
84
+ 此时,所有静态资源都会添加`https://xxx/`前缀
85
+
86
+ ### svgr
87
+ 打包时将svg作为一个React组件处理,options参考[svgr](https://react-svgr.com/docs/options/),另外还支持了`include`和`exclude`两个配置项,用于匹配需要处理的svg文件
88
+ - type: `boolean | Object`
89
+ - default: `true`
90
+
91
+ #### include
92
+ 设定匹配的svg文件
93
+ - type: `string | RegExp | (string | RegExp)[]`
94
+ - default: `/\.svg$/`
95
+
96
+ #### exclude
97
+ 设定不匹配的svg文件
98
+ - type: `string | RegExp | (string | RegExp)[]`
99
+ - default: `undefined`
100
+
101
+
102
+ ## autoExternal
103
+ 自动外置项目的dependencies和peerDependencies,不会将其打包到最终的bundle中
104
+ - type: `boolean | Object`
105
+ - default: `true`
106
+
107
+ ### dependencies
108
+ 是否需要外置项目的dep依赖
109
+ - type: `boolean`
110
+ - default: `true`
111
+
112
+ ### peerDependencies
113
+ 是否需要外置项目的peerDep依赖
114
+ - type: `boolean`
115
+ - default: `true`
116
+
117
+ ## buildType
118
+ 构建类型,`bundle`会打包你的代码,`bundleless`只做代码的转换
119
+ - type: `'bundle' | 'bundleless'`
120
+ - default: `bundle`
121
+
122
+ ## copy
123
+
124
+ 将文件或目录拷贝到指定位置。
125
+
126
+ - type: `Object`
127
+ ```ts modern.config.ts
128
+ import { defineConfig } from '@modern-js/module-tools';
129
+
130
+
131
+ export default defineConfig({
132
+ buildConfig: {
133
+ copy: {
134
+ patterns: [{ from: './src/assets', to: '' }],
135
+ },
136
+ },
137
+ });
138
+ ```
139
+
140
+ ### `copy.patterns`
141
+
142
+ - type: `CopyPattern[]`
143
+ - default: `[]`
144
+
145
+ ``` ts
146
+ export interface CopyPattern {
147
+ from: string;
148
+ to?: string;
149
+ context?: string;
150
+ globOptions?: globby.GlobbyOptions;
151
+ }
152
+ ```
153
+
154
+ ### copy.options
155
+
156
+ - type: `Object`
157
+ - default: `{ concurrency: 100, enableCopySync: false }`
158
+
159
+ ``` ts
160
+ type Options = {
161
+ concurrency?: number;
162
+ enableCopySync?: boolean;
163
+ };
164
+ ```
165
+
166
+ * `concurrency`: 指定并行执行多少个复制任务。
167
+ * `enableCopySync`: 使用 [`fs.copySync`](https://github.com/jprichardson/node-fs-extra/blob/master/lib/copy/copy-sync.js),默认情况下 [`fs.copy`](https://github.com/jprichardson/node-fs-extra/blob/master/lib/copy/copy.js)。
168
+
169
+ ## define
170
+ 定义全局变量,会被注入到代码中
171
+ - type: `Record<string, string>`
172
+ - default: `{}`
173
+
174
+ 由于`define`功能是由全局文本替换实现的,所以需要保证全局变量值为字符串,更为安全的做法是将每个全局变量的值转化为字符串,使用`JSON.stringify`进行转换,如下所示:
175
+ ```ts modern.config.ts
176
+ import { defineConfig } from '@modern-js/module-tools';
177
+
178
+ export default defineConfig({
179
+ buildConfig: {
180
+ define: {
181
+ 'VERSION': JSON.stringify('1.0'),
182
+
183
+ },
184
+ },
185
+ });
186
+ ```
187
+
188
+ :::tip
189
+ 为了防止全局替换替换过度,建议使用时遵循以下两个原则:
190
+ - 全局常量使用大写
191
+ - 自定义全局常量前缀后缀,确保独一无二
192
+ :::
193
+
194
+ ## dts
195
+ dts文件生成相关配置,默认会生成
196
+
197
+ - type: `false | Object`
198
+ - default: `{}`
199
+
200
+ ### tsconfigPath
201
+ tsconfig文件的路径
202
+ - type: `string`
203
+ - default: `./tsconfig.json`
204
+
205
+ ### distPath
206
+ dts文件的输出路径,基于[outdir]('/zh/api/build-config/#outdir')进行输出
207
+ - type: `string`
208
+ - default: `./types`
209
+
210
+ ### only
211
+ 只生成dts文件,不生成js文件
212
+ - type: `boolean`
213
+ - default: `false`
214
+
215
+ ## externals
216
+ 配置外部依赖,不会被打包到最终的bundle中
217
+ - type: `(string | RegExp)[]`
218
+ - default: `[]`
219
+ ## format
220
+ js产物输出的格式,其中`iife`和`umd`只能在`buildType`为`bundle`时生效
221
+ - type: `'esm' | 'cjs' | 'iife' | 'umd'`
222
+ - default: `cjs`
223
+
224
+ ## input
225
+ 指定构建的入口文件,数组形式可以指定目录
226
+ - type: `string[] | Record<string, string>`
227
+ - default: `bundle`模式下默认为`['src/index.ts']`,`bundleless`模式下默认为`['src']`
228
+
229
+ ```ts modern.config.ts
230
+ import { defineConfig } from '@modern-js/module-tools';
231
+
232
+ export default defineConfig({
233
+ buildConfig: {
234
+ input: ['src/index.ts', 'src/index2.ts'],
235
+ },
236
+ });
237
+ ```
238
+
239
+ ## jsx
240
+ 指定jsx的编译方式, 默认支持React17以上,自动注入jsx运行时代码
241
+ - type: `automatic | classic`
242
+ - default: `automatic`
243
+
244
+ ## minify
245
+ 使用esbuild或者terser压缩代码,也可以传入[terserOptions](https://github.com/terser/terser#minify-options)
246
+ - type: `'terser' | 'esbuild' | false | Object`
247
+ - default: `false`
248
+
249
+ ```ts modern.config.ts
250
+ import { defineConfig } from '@modern-js/module-tools';
251
+
252
+ export default defineConfig({
253
+ buildConfig: {
254
+ minify: {
255
+ compress: {
256
+ drop_console: true,
257
+ },
258
+ },
259
+ },
260
+ });
261
+ ```
262
+
263
+ ## outdir
264
+ 指定构建的输出目录
265
+ - type: `string`
266
+ - default: `dist`
267
+
268
+ ## platform
269
+ 默认生成用于node环境下的代码,你也可以指定为`browser`,会生成用于浏览器环境的代码
270
+ - type: `'browser' | 'node'`
271
+ - default: `node`
272
+
273
+ ## sourceDir
274
+ 指定构建的源码目录,默认为`src`,用于在`bundleless`构建时基于源码目录结构生成对应的产物目录
275
+ - type: `string`
276
+ - default: `src`
277
+
278
+ ## sourceMap
279
+ 是否生成sourceMap
280
+ - type: `boolean | 'inline' | 'external'`
281
+ - default: `false`
282
+
283
+ ## splitting
284
+ 是否开启代码分割
285
+ - type: `boolean`
286
+ - default: `false`
287
+
288
+ ## style
289
+ 配置样式相关的配置
290
+
291
+ ### less
292
+ less相关配置
293
+ #### lessOptions
294
+ 详细配置参考[less](https://less.bootcss.com/usage/#less-options)
295
+ - type: `Object`
296
+ - default: `{ javascriptEnabled: true }`
297
+
298
+ #### additionalData
299
+ 在入口文件起始添加 `Less` 代码。
300
+ - type: `string`
301
+ - default: `undefined`
302
+
303
+ ```ts modern.config.ts
304
+ import { defineConfig } from '@modern-js/module-tools';
305
+
306
+ export default defineConfig({
307
+ buildConfig: {
308
+ style: {
309
+ less: {
310
+ additionalData: `@base-color: #c6538c;`,
311
+ },
312
+ }
313
+ }
314
+ });
315
+
316
+ ```
317
+ #### implementation
318
+ 配置 `Less` 使用的实现库,在不指定的情况下,使用的内置版本是`4.1.3`
319
+ - type: `string | Object`
320
+ - default: `undefined`
321
+
322
+ `Object` 类型时,指定 `Less` 的实现库
323
+ ```ts modern.config.ts
324
+ import { defineConfig } from '@modern-js/module-tools';
325
+
326
+ export default defineConfig({
327
+ buildConfig: {
328
+ style: {
329
+ less: {
330
+ implementation: require('less'),
331
+ },
332
+ }
333
+ }
334
+ });
335
+ ```
336
+
337
+ `string` 类型时,指定 `Less` 的实现库的路径
338
+ ```ts modern.config.ts
339
+ import { defineConfig } from '@modern-js/module-tools';
340
+
341
+ export default defineConfig({
342
+ buildConfig: {
343
+ style: {
344
+ less: {
345
+ implementation: require.resolve('less'),
346
+ },
347
+ }
348
+ }
349
+ });
350
+ ```
351
+
352
+ ### sass
353
+ sass相关配置
354
+ #### sassOptions
355
+ 详细配置参考[node-sass](https://github.com/sass/node-sass#options)
356
+ - type: `Object`
357
+ - default: `{}`
358
+ #### additionalData
359
+ 在入口文件起始添加 `Sass` 代码。
360
+ - type: `string | Function`
361
+ - default: `undefined`
362
+ ```ts modern.config.ts
363
+ import { defineConfig } from '@modern-js/module-tools';
364
+
365
+ export default defineConfig({
366
+ buildConfig: {
367
+ style: {
368
+ sass: {
369
+ additionalData: `$base-color: #c6538c;
370
+ $border-dark: rgba($base-color, 0.88);`,
371
+ },
372
+ }
373
+ }
374
+ });
375
+ ```
376
+
377
+ #### implementation
378
+ 配置 `Sass` 使用的实现库,在不指定的情况下,使用的内置版本是`1.5.4`
379
+ - type: `string | Object`
380
+ - default: `undefined`
381
+
382
+ `Object` 类型时,指定 `Sass` 的实现库
383
+ ```ts modern.config.ts
384
+ import { defineConfig } from '@modern-js/module-tools';
385
+
386
+ export default defineConfig({
387
+ buildConfig: {
388
+ style: {
389
+ sass: {
390
+ implementation: require('sass'),
391
+ },
392
+ }
393
+ }
394
+ });
395
+ ```
396
+
397
+ `string` 类型时,指定 `Sass` 的实现库的路径
398
+ ```ts modern.config.ts
399
+ import { defineConfig } from '@modern-js/module-tools';
400
+
401
+ export default defineConfig({
402
+ buildConfig: {
403
+ style: {
404
+ sass: {
405
+ implementation: require.resolve('sass'),
406
+ },
407
+ }
408
+ }
409
+ });
410
+ ```
411
+
412
+ ### postcss
413
+ - plugins
414
+ - processOptions
415
+
416
+ 详细配置查看[postcss](https://github.com/postcss/postcss#options)
417
+ ### inject
418
+ 配置打包模式下是否将style插入到js中
419
+
420
+ - type: `boolean`
421
+ - default: `false`
422
+
423
+ ### autoModules
424
+ 根据文件名自动启用 CSS Modules。
425
+
426
+ - type: `boolean | RegExp`
427
+ - default: `true `
428
+
429
+ `true` : 为以 `.module.css` `.module.less` `.module.scss` `.module.sass` 文件名结尾的样式文件启用 CSS Modules
430
+
431
+ `false` : 禁用 CSS Modules.
432
+
433
+ `RegExp` : 为匹配正则条件的所有文件启用 CSS Modules.
434
+
435
+
436
+ ### modules
437
+ CSS Modules配置
438
+
439
+ - type: `Object`
440
+ - default: `{}`
441
+
442
+ 一个常用的配置是`localsConvention`,它可以改变css modules的类名生成规则
443
+ ```ts modern.config.ts
444
+ import { defineConfig } from '@modern-js/module-tools';
445
+
446
+ export default defineConfig({
447
+ buildConfig: {
448
+ style: {
449
+ modules: {
450
+ localsConvention: 'camelCaseOnly',
451
+ },
452
+ }
453
+ }
454
+ });
455
+ ```
456
+ 对于以下样式
457
+ ```css
458
+ .box-title {
459
+ color: red;
460
+ }
461
+ ```
462
+ 你可以使用`styles.boxTitle`来访问
463
+
464
+
465
+ 详细配置查看[postcss-modules](https://github.com/madyankin/postcss-modules#usage)
466
+
467
+ ### tailwind
468
+ tailwindcss相关配置
469
+
470
+ - type: `Object | Function`
471
+ - default: `见下方配置详情`
472
+
473
+ <details>
474
+ <summary>TailwindCSS 配置详情</summary>
475
+
476
+ ```ts modern.config.ts
477
+ const tailwind = {
478
+ purge: {
479
+ enabled: options.env === 'production',
480
+ content: [
481
+ './config/html/**/*.html',
482
+ './config/html/**/*.ejs',
483
+ './config/html/**/*.hbs',
484
+ './src/**/*',
485
+ ],
486
+ layers: ['utilities'],
487
+ },
488
+ // https://tailwindcss.com/docs/upcoming-changes
489
+ future: {
490
+ removeDeprecatedGapUtilities: false,
491
+ purgeLayersByDefault: true,
492
+ defaultLineHeights: false,
493
+ standardFontWeights: false,
494
+ },
495
+ }
496
+ ```
497
+
498
+ 值为 `Object` 类型时,与默认配置通过 `Object.assign` 合并。
499
+
500
+ 值为 `Function` 类型时,函数返回的对象与默认配置通过 `Object.assign` 合并。
501
+
502
+ 不允许出现 `theme` 属性,否则会构建失败, 使用 [`designSystem`](/zh/api/design-system) 作为 `Tailwind CSS Theme` 配置。
503
+
504
+ 其他的使用方式和 Tailwind CSS 一致: [快速传送门](https://tailwindcss.com/docs/configuration)。
505
+
506
+
507
+ ## target
508
+ 指定构建的目标环境
509
+ - type: `'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'esnext'`
510
+ - default: `'es2015'`
511
+
512
+
513
+ ## umdGlobals
514
+ 指定umd产物外部导入的全局变量
515
+ - type: `Record<string, string>`
516
+ - default: `{}`
517
+
518
+ ```ts modern.config.ts
519
+ import { defineConfig } from '@modern-js/module-tools';
520
+
521
+ export default defineConfig({
522
+ buildConfig: {
523
+ umdGlobals: {
524
+ react: 'React',
525
+ 'react-dom': 'ReactDOM',
526
+ },
527
+ }
528
+ });
529
+ ```
530
+ 此时,`react`和`react-dom`会被看做是外部导入的全局变量,不会被打包进umd产物中,而是通过`global.React`和`global.ReactDOM`的方式进行访问
531
+
532
+ ## umdModuleName
533
+ 指定umd产物的模块名
534
+
535
+ - type: `string` | `Function`
536
+ - default: `name => name`
537
+
538
+ ```ts modern.config.ts
539
+ import { defineConfig } from '@modern-js/module-tools';
540
+
541
+ export default defineConfig({
542
+ buildConfig: {
543
+ format: 'umd',
544
+ umdModuleName: 'myLib',
545
+ }
546
+ });
547
+ ```
548
+ 此时umd产物会去挂载到`global.myLib`上
549
+ :::tip
550
+ - 需要遵守umd规范,umd产物的模块名不能和全局变量名冲突
551
+ - 模块名不能含有`-`,`@`,`/`等特殊字符
552
+ :::
553
+
554
+ 同时函数形式可以接收一个参数,为当前打包文件的输出路径
555
+ ```ts modern.config.ts
556
+ import { defineConfig } from '@modern-js/module-tools';
557
+
558
+ export default defineConfig({
559
+ buildConfig: {
560
+ format: 'umd',
561
+ umdModuleName: (path) => {
562
+ if (path.includes('index')) {
563
+ return 'myLib';
564
+ } else {
565
+ return 'myLib2';
566
+ }
567
+ },
568
+ }
569
+ });
570
+ ```