@modern-js/module-tools-docs 2.3.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`.
@@ -50,17 +50,17 @@ export const buildConfig = [
50
50
  format: 'cjs',
51
51
  target: 'es6',
52
52
  buildType: 'bundle',
53
- outDir: '. /lib',
53
+ outDir: './dist/lib',
54
54
  },
55
55
  {
56
56
  format: 'esm',
57
57
  target: 'es6',
58
58
  buildType: 'bundle',
59
- outDir: '. /es',
59
+ outDir: './dist/es',
60
60
  },
61
61
  {
62
62
  buildType: 'bundle',
63
- outDir: '. /types',
63
+ outDir: './dist/types',
64
64
  dts: {
65
65
  only: true,
66
66
  },
@@ -89,23 +89,23 @@ export const buildConfig = [
89
89
  format: 'cjs',
90
90
  target: 'es6',
91
91
  buildType: 'bundle',
92
- outDir: '. /lib',
92
+ outDir: './dist/lib',
93
93
  },
94
94
  {
95
95
  format: 'esm',
96
96
  target: 'es6',
97
97
  buildType: 'bundle',
98
- outDir: '. /es',
98
+ outDir: './dist/es',
99
99
  },
100
100
  {
101
101
  format: 'umd',
102
102
  target: 'es6',
103
103
  buildType: 'bundle',
104
- outDir: '. /umd',
104
+ outDir: './dist/umd',
105
105
  },
106
106
  {
107
107
  buildType: 'bundle',
108
- outDir: '. /types',
108
+ outDir: './dist/types',
109
109
  dts: {
110
110
  only: true,
111
111
  },
@@ -135,17 +135,17 @@ export const buildConfig = [
135
135
  format: 'cjs',
136
136
  target: 'es6',
137
137
  buildType: 'bundleless',
138
- outDir: '. /lib',
138
+ outDir: './dist/lib',
139
139
  },
140
140
  {
141
141
  format: 'esm',
142
142
  target: 'es6',
143
143
  buildType: 'bundleless',
144
- outDir: '. /es',
144
+ outDir: './dist/es',
145
145
  },
146
146
  {
147
147
  buildType: 'bundleless',
148
- outDir: '. /types',
148
+ outDir: './dist/types',
149
149
  dts: {
150
150
  only: true,
151
151
  },
@@ -172,23 +172,23 @@ export const buildConfig = [
172
172
  format: 'cjs',
173
173
  target: 'es6',
174
174
  buildType: 'bundleless',
175
- outDir: '. /lib',
175
+ outDir: './dist/lib',
176
176
  },
177
177
  {
178
178
  format: 'esm',
179
179
  target: 'es6',
180
180
  buildType: 'bundleless',
181
- outDir: '. /es',
181
+ outDir: './dist/es',
182
182
  },
183
183
  {
184
184
  format: 'umd',
185
185
  target: 'es6',
186
186
  buildType: 'bundle',
187
- outDir: '. /umd',
187
+ outDir: './dist/umd',
188
188
  },
189
189
  {
190
190
  buildType: 'bundleless',
191
- outDir: '. /types',
191
+ outDir: './dist/types',
192
192
  dts: {
193
193
  only: true,
194
194
  },
@@ -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
- ```js modern.config.ts
660
+ ```ts modern.config.ts
623
661
  import { defineConfig } from '@modern-js/module-tools';
624
662
 
625
663
  export default defineConfig({
@@ -50,17 +50,17 @@ export const buildConfig = [
50
50
  format: 'cjs',
51
51
  target: 'es6',
52
52
  buildType: 'bundle',
53
- outDir: './lib',
53
+ outDir: './dist/lib',
54
54
  },
55
55
  {
56
56
  format: 'esm',
57
57
  target: 'es6',
58
58
  buildType: 'bundle',
59
- outDir: './es',
59
+ outDir: './dist/es',
60
60
  },
61
61
  {
62
62
  buildType: 'bundle',
63
- outDir: './types',
63
+ outDir: './dist/types',
64
64
  dts: {
65
65
  only: true,
66
66
  },
@@ -89,23 +89,23 @@ export const buildConfig = [
89
89
  format: 'cjs',
90
90
  target: 'es6',
91
91
  buildType: 'bundle',
92
- outDir: './lib',
92
+ outDir: './dist/lib',
93
93
  },
94
94
  {
95
95
  format: 'esm',
96
96
  target: 'es6',
97
97
  buildType: 'bundle',
98
- outDir: './es',
98
+ outDir: './dist/es',
99
99
  },
100
100
  {
101
101
  format: 'umd',
102
102
  target: 'es6',
103
103
  buildType: 'bundle',
104
- outDir: './umd',
104
+ outDir: './dist/umd',
105
105
  },
106
106
  {
107
107
  buildType: 'bundle',
108
- outDir: './types',
108
+ outDir: './dist/types',
109
109
  dts: {
110
110
  only: true,
111
111
  },
@@ -135,17 +135,17 @@ export const buildConfig = [
135
135
  format: 'cjs',
136
136
  target: 'es6',
137
137
  buildType: 'bundleless',
138
- outDir: './lib',
138
+ outDir: './dist/lib',
139
139
  },
140
140
  {
141
141
  format: 'esm',
142
142
  target: 'es6',
143
143
  buildType: 'bundleless',
144
- outDir: './es',
144
+ outDir: './dist/es',
145
145
  },
146
146
  {
147
147
  buildType: 'bundleless',
148
- outDir: './types',
148
+ outDir: './dist/types',
149
149
  dts: {
150
150
  only: true,
151
151
  },
@@ -172,23 +172,23 @@ export const buildConfig = [
172
172
  format: 'cjs',
173
173
  target: 'es6',
174
174
  buildType: 'bundleless',
175
- outDir: './lib',
175
+ outDir: './dist/lib',
176
176
  },
177
177
  {
178
178
  format: 'esm',
179
179
  target: 'es6',
180
180
  buildType: 'bundleless',
181
- outDir: './es',
181
+ outDir: './dist/es',
182
182
  },
183
183
  {
184
184
  format: 'umd',
185
185
  target: 'es6',
186
186
  buildType: 'bundle',
187
- outDir: './umd',
187
+ outDir: './dist/umd',
188
188
  },
189
189
  {
190
190
  buildType: 'bundleless',
191
- outDir: './types',
191
+ outDir: './dist/types',
192
192
  dts: {
193
193
  only: true,
194
194
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/module-tools-docs",
3
- "version": "2.3.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-tools": "2.3.0",
15
- "@modern-js/doc-plugin-auto-sidebar": "2.3.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",