@modern-js/module-tools-docs 2.15.0 → 2.16.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @modern-js/module-tools-docs
2
2
 
3
+ ## 2.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b06f571: docs: 新增 buildConfig api 和更新 plugin-import 内容
8
+ docs: add buildConfig api content and update plugin-import content
9
+
10
+ ### Patch Changes
11
+
12
+ - 4e876ab: chore: package.json include the monorepo-relative directory
13
+
14
+ chore: 在 package.json 中声明 monorepo 的子路径
15
+
16
+ - Updated dependencies [628be4b]
17
+ - Updated dependencies [4e876ab]
18
+ - @modern-js/doc-tools@2.16.0
19
+ - @modern-js/doc-plugin-auto-sidebar@2.16.0
20
+
3
21
  ## 2.15.0
4
22
 
5
23
  ### Patch Changes
@@ -234,6 +234,15 @@ To prevent excessive global replacement substitution, it is recommended that the
234
234
 
235
235
  :::
236
236
 
237
+ <!-- ## disableSwcTransform
238
+
239
+ Starting with version 2.16.0, SWC Transform is enabled by default for code transformation. If you want to disable this feature, you can use this configuration. Only Esbuild Transform is used in this case.
240
+
241
+ The use of SWC Transform can reduce the impact of auxiliary functions on the volume of the constructed product.
242
+
243
+ * **Type**: `boolean`
244
+ * **Default**: `false` -->
245
+
237
246
  ## dts
238
247
 
239
248
  The dts file generates the relevant configuration, by default it generates.
@@ -313,6 +322,50 @@ We have done many extensions based on the original esbuild build. Therefore, whe
313
322
 
314
323
  :::
315
324
 
325
+ <!-- ## externalHelpers
326
+
327
+ By default, the output JS code may depend on helper functions to support the target environment or output format, and these helper functions will be inlined in the file that requires it.
328
+
329
+ When using SWC Transform for code transformation, you can enable the `externalHelpers` configuration to convert inline helper functions to import them from the external module `@swc/helpers`.
330
+
331
+ * **Type**: `boolean`
332
+ * **Default**: `false`
333
+
334
+ Below is a comparison of the product changes before and after using this configuration.
335
+
336
+ Before enable:
337
+
338
+ ``` js ./dist/index.js
339
+ // helper function
340
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
341
+ // ...
342
+ }
343
+ // helper function
344
+ function _async_to_generator(fn) {
345
+ return function() {
346
+ // use asyncGeneratorStep
347
+ // ...
348
+ };
349
+ }
350
+
351
+ // your code
352
+ export var yourCode = function() {
353
+ // use _async_to_generator
354
+ }
355
+ ```
356
+
357
+ After enabled:
358
+
359
+ ``` js ./dist/index.js
360
+ // helper functions imported from @swc/helpers
361
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
362
+
363
+ // your code
364
+ export var yourCode = function() {
365
+ // use _async_to_generator
366
+ }
367
+ ``` -->
368
+
316
369
  ## externals
317
370
 
318
371
  Configure external dependencies that will not be packaged into the final bundle
@@ -468,6 +521,13 @@ Whether to generate sourceMap or not
468
521
  - type: `boolean | 'inline' | 'external'`
469
522
  - default: `false`
470
523
 
524
+ <!-- ## sourceType
525
+
526
+ Sets the format of the source code. By default, the source code will be treated as EsModule. When the source code is using CommonJS, you need to set `commonjs`.
527
+
528
+ - **Type**: `commonjs` | `module`
529
+ - **Default**: `module` -->
530
+
471
531
  ## splitting
472
532
 
473
533
  Whether to enable code splitting
@@ -739,6 +799,40 @@ Specify the target environment for the build
739
799
  - type: `'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'esnext'`
740
800
  - default: `'es6'`
741
801
 
802
+ <!-- ## transformImport
803
+
804
+ Using [SWC](https://swc.rs/) provides the same ability and configuration as [`babel-plugin-import`](https://github.com/umijs/babel-plugin-import).
805
+
806
+ * **Type**: `Array`
807
+ * **Default**: `[]`
808
+
809
+ The elements of the array are configuration objects for `babel-plugin-import`, which can be referred to [options](https://github.com/umijs/babel-plugin-import#options)。
810
+
811
+ **Example:**
812
+
813
+ ```ts
814
+ import moduleTools, { defineConfig} from '@modern-js/module-tools';
815
+
816
+ export default defineConfig({
817
+ buildConfig: {
818
+ transformImport: [
819
+ // babel-plugin-import`s options config
820
+ {
821
+ libraryName: 'foo',
822
+ style: true,
823
+ },
824
+ ],
825
+ },
826
+ plugins: [
827
+ moduleTools(),
828
+ ],
829
+ });
830
+ ```
831
+
832
+ ### Notes
833
+
834
+ Reference the [Import Plugin - Notes](plugins/official-list/plugin-import.html#Notes) -->
835
+
742
836
  ## umdGlobals
743
837
 
744
838
  Specify global variables for external import of umd products
@@ -2,6 +2,12 @@
2
2
 
3
3
  Using [SWC](https://swc.rs/) provides the same ability and configuration as [`babel-plugin-import`](https://github.com/umijs/babel-plugin-import).
4
4
 
5
+ {/*
6
+ :::tip
7
+ [As of @modern-js/module-tools version 2.16.0, this plugin functionality is built into module-tools and is provided by [`transformImport`](api/config/build-config.html#transformimport).]: #
8
+ :::
9
+ */}
10
+
5
11
  ## Quick Start
6
12
 
7
13
  ### Install
@@ -275,6 +275,15 @@ export default defineConfig({
275
275
 
276
276
  :::
277
277
 
278
+ <!-- ## disableSwcTransform
279
+
280
+ 从 2.16.0 版本开始,默认开启 SWC Transform 进行代码转换。如果想要关闭该功能,可以使用该配置。此时仅使用 Esbuild Transform。
281
+
282
+ 使用 SWC Transform 可以减小辅助函数对构建产物体积的影响。
283
+
284
+ * 类型:`boolean`
285
+ * 默认值:`false` -->
286
+
278
287
  ## dts
279
288
 
280
289
  类型文件生成的相关配置,默认情况会生成。
@@ -354,6 +363,52 @@ export default defineConfig({
354
363
 
355
364
  :::
356
365
 
366
+ <!-- ## externalHelpers
367
+
368
+ 默认情况下,输出的 JS 代码可能会依赖一些辅助函数来支持目标环境或者输出格式,这些辅助函数会被内联在需要它的文件中。
369
+
370
+ 当在使用 SWC Transform 进行代码转换的时候,可以启动 `externalHelpers` 配置,将内联的辅助函数转换为从外部模块 `@swc/helpers` 导入这些辅助函数。
371
+
372
+ * 类型:`boolean`
373
+ * 默认值:`false`
374
+
375
+
376
+ 下面是使用该配置前后的产物变化比较。
377
+
378
+ 开启前:
379
+
380
+ ``` js ./dist/index.js
381
+ // 辅助函数
382
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
383
+ // ...
384
+ }
385
+ // 辅助函数
386
+ function _async_to_generator(fn) {
387
+ return function() {
388
+ // use asyncGeneratorStep
389
+ // ...
390
+ };
391
+ }
392
+
393
+ // 你的代码
394
+ export var yourCode = function() {
395
+ // use _async_to_generator
396
+ }
397
+ ```
398
+
399
+ 开启后:
400
+
401
+ ``` js ./dist/index.js
402
+ // 从 @swc/helpers 导入的辅助函数
403
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
404
+
405
+ // 你的代码
406
+ export var yourCode = function() {
407
+ // use _async_to_generator
408
+ }
409
+ ``` -->
410
+
411
+
357
412
  ## externals
358
413
 
359
414
  配置外部依赖,不会被打包到最终的 bundle 中。
@@ -514,6 +569,13 @@ export default defineConfig({
514
569
  - 类型: `boolean | 'inline' | 'external'`
515
570
  - 默认值: `false`
516
571
 
572
+ <!-- ## sourceType
573
+
574
+ 设置源码的格式。默认情况下,会将源码作为 EsModule 进行处理。当源码使用的是 CommonJS 的时候,需要设置 `commonjs`。
575
+
576
+ - 类型:`commonjs` | `module`
577
+ - 默认值:`module` -->
578
+
517
579
  ## splitting
518
580
 
519
581
  是否开启代码分割。
@@ -799,6 +861,41 @@ const tailwind = {
799
861
  - 类型: `'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'esnext'`
800
862
  - 默认值: `'es6'`
801
863
 
864
+ <!-- ## transformImport
865
+
866
+ 提供与 babel-plugin-import 等价的能力和配置,基于 SWC 实现。
867
+
868
+ * 类型:`Array`
869
+ * 默认值:`[]`
870
+
871
+ 数组元素为一个 babel-plugin-import 的配置对象。配置对象可以参考 [options](https://github.com/umijs/babel-plugin-import#options)。
872
+
873
+ 使用示例:
874
+
875
+ ```ts
876
+ import moduleTools, { defineConfig} from '@modern-js/module-tools';
877
+
878
+ export default defineConfig({
879
+ buildConfig: {
880
+ transformImport: [
881
+ // babel-plugin-import 的 options 配置
882
+ {
883
+ libraryName: 'foo',
884
+ style: true,
885
+ },
886
+ ],
887
+ },
888
+ plugins: [
889
+ moduleTools(),
890
+ ],
891
+ });
892
+ ```
893
+
894
+ ### 注意事项
895
+
896
+ 参考[【Import 插件——注意事项】](plugins/official-list/plugin-import.html#注意事项) -->
897
+
898
+
802
899
  ## umdGlobals
803
900
 
804
901
  指定 UMD 产物外部导入的全局变量。
@@ -2,6 +2,13 @@
2
2
 
3
3
  提供与 [babel-plugin-import](https://github.com/umijs/babel-plugin-import) 等价的能力和配置,基于 [SWC](https://swc.rs/) 实现。
4
4
 
5
+ {/*
6
+ :::tip
7
+ 从 @modern-js/module-tools 2.16.0 版本开始,该插件功能内置在 module-tools 中,由 [`transformImport`](api/config/build-config.html#transformimport)
8
+ 配置提供。
9
+ :::
10
+ */}
11
+
5
12
  ## 快速开始
6
13
 
7
14
  ### 安装
package/package.json CHANGED
@@ -3,17 +3,21 @@
3
3
  "description": "Shared documentation of Modern.js Module Tools",
4
4
  "homepage": "https://modernjs.dev/module-tools",
5
5
  "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
- "repository": "web-infra-dev/modern.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/web-infra-dev/modern.js",
9
+ "directory": "packages/document/module-doc"
10
+ },
7
11
  "license": "MIT",
8
- "version": "2.15.0",
12
+ "version": "2.16.0",
9
13
  "main": "index.js",
10
14
  "dependencies": {
11
15
  "@code-hike/mdx": "^0.7.4",
12
16
  "react": "^18.2.0",
13
17
  "react-dom": "^18.2.0",
14
18
  "shiki": "^0.11.1",
15
- "@modern-js/doc-plugin-auto-sidebar": "2.15.0",
16
- "@modern-js/doc-tools": "2.15.0"
19
+ "@modern-js/doc-plugin-auto-sidebar": "2.16.0",
20
+ "@modern-js/doc-tools": "2.16.0"
17
21
  },
18
22
  "scripts": {
19
23
  "dev": "modern dev",