@modern-js/module-tools-docs 2.4.0 → 2.4.1-beta.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.
|
@@ -285,6 +285,44 @@ Generates code for the node environment by default, you can also specify `browse
|
|
|
285
285
|
- type: `'browser' | 'node'`
|
|
286
286
|
- default: `node`
|
|
287
287
|
|
|
288
|
+
## sideEffects
|
|
289
|
+
|
|
290
|
+
Module sideEffects
|
|
291
|
+
|
|
292
|
+
- Type: `RegExg[] | (filePath: string, isExternal: boolean) => boolean | boolean`
|
|
293
|
+
- Default value: `undefined`
|
|
294
|
+
|
|
295
|
+
Normally, we configure the module's side effects via the sideEffects field in package.json, but in some cases, such as when we reference a three-party package style file
|
|
296
|
+
|
|
297
|
+
```js
|
|
298
|
+
import 'other-package/dist/index.css'
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
But the package.json of this three-party package does not have the style file configured in the sideEffects
|
|
302
|
+
|
|
303
|
+
```json other-package/package.json
|
|
304
|
+
{
|
|
305
|
+
"sideEffects": ["dist/index.js"]
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
This is the time to use this configuration item, which supports regular and functional forms
|
|
310
|
+
|
|
311
|
+
```js modern.config.ts
|
|
312
|
+
import { defineConfig } from '@modern-js/module-tools';
|
|
313
|
+
export default defineConfig({
|
|
314
|
+
buildConfig: {
|
|
315
|
+
sideEffects: [/\.css$/],
|
|
316
|
+
// or
|
|
317
|
+
// sideEffects: (filePath, isExternal) => /\.css$/.test(filePath),
|
|
318
|
+
},
|
|
319
|
+
});
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
:::tip
|
|
323
|
+
After adding this configuration, the sideEffects field in package.json will no longer be read when packaging
|
|
324
|
+
:::
|
|
325
|
+
|
|
288
326
|
## sourceDir
|
|
289
327
|
|
|
290
328
|
Specify the source directory of the build, default is `src`, which is used to generate the corresponding product directory based on the source directory structure when building `bundleless`.
|
|
@@ -342,6 +342,44 @@ export default defineConfig({
|
|
|
342
342
|
- 类型: `'browser' | 'node'`
|
|
343
343
|
- 默认值: `node`
|
|
344
344
|
|
|
345
|
+
## sideEffects
|
|
346
|
+
|
|
347
|
+
配置模块的副作用
|
|
348
|
+
|
|
349
|
+
- 类型: `RegExg[] | (filePath: string, isExternal: boolean) => boolean | boolean`
|
|
350
|
+
- 默认值: `undefined`
|
|
351
|
+
|
|
352
|
+
通常情况下,我们通过 package.json 的 `"sideEffects"` 字段来配置模块的副作用,但是在某些情况下,例如我们引用了一个三方包的样式文件。
|
|
353
|
+
|
|
354
|
+
```js
|
|
355
|
+
import 'other-package/dist/index.css'
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
但是这个三方包的 package.json 里并没有将样式文件配置到 `"sideEffects"` 里。
|
|
359
|
+
|
|
360
|
+
```json other-package/package.json
|
|
361
|
+
{
|
|
362
|
+
"sideEffects": ["dist/index.js"]
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
这时候就可以使用这个配置项,支持正则和函数形式。
|
|
367
|
+
|
|
368
|
+
```js modern.config.ts
|
|
369
|
+
import { defineConfig } from '@modern-js/module-tools';
|
|
370
|
+
export default defineConfig({
|
|
371
|
+
buildConfig: {
|
|
372
|
+
sideEffects: [/\.css$/],
|
|
373
|
+
// or
|
|
374
|
+
// sideEffects: (filePath, isExternal) => /\.css$/.test(filePath),
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
:::tip
|
|
380
|
+
添加此配置后,打包时将不会再读取 package.json 里的 `"sideEffects"` 字段。
|
|
381
|
+
:::
|
|
382
|
+
|
|
345
383
|
## sourceDir
|
|
346
384
|
|
|
347
385
|
指定构建的源码目录,默认为 `src`,用于在 `bundleless` 构建时基于源码目录结构生成对应的产物目录。
|
|
@@ -619,7 +657,7 @@ const tailwind = {
|
|
|
619
657
|
- 类型: `Record<string, string>`
|
|
620
658
|
- 默认值: `{}`
|
|
621
659
|
|
|
622
|
-
```
|
|
660
|
+
```ts modern.config.ts
|
|
623
661
|
import { defineConfig } from '@modern-js/module-tools';
|
|
624
662
|
|
|
625
663
|
export default defineConfig({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/module-tools-docs",
|
|
3
|
-
"version": "2.4.0",
|
|
3
|
+
"version": "2.4.1-beta.0",
|
|
4
4
|
"description": "docs",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [],
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"react": "^18.2.0",
|
|
12
12
|
"react-dom": "^18.2.0",
|
|
13
13
|
"shiki": "^0.11.1",
|
|
14
|
-
"@modern-js/doc-plugin-auto-sidebar": "2.4.0",
|
|
15
|
-
"@modern-js/doc-tools": "2.4.0"
|
|
14
|
+
"@modern-js/doc-plugin-auto-sidebar": "2.4.1-beta.0",
|
|
15
|
+
"@modern-js/doc-tools": "2.4.1-beta.0"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"dev": "modern dev",
|