@modern-js/module-tools-docs 2.28.0 → 2.30.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,20 @@
1
1
  # @modern-js/module-tools-docs
2
2
 
3
+ ## 2.30.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [c03be09]
8
+ - @modern-js/doc-tools@2.30.0
9
+ - @modern-js/doc-plugin-auto-sidebar@2.30.0
10
+
11
+ ## 2.29.0
12
+
13
+ ### Patch Changes
14
+
15
+ - @modern-js/doc-plugin-auto-sidebar@2.29.0
16
+ - @modern-js/doc-tools@2.29.0
17
+
3
18
  ## 2.28.0
4
19
 
5
20
  ### Patch Changes
@@ -217,7 +217,7 @@ Whether to require peerDep dependencies for external projects
217
217
  The build type, `bundle` will package your code, `bundleless` will only do the code conversion
218
218
 
219
219
  - **Type**: `'bundle' | 'bundleless'`
220
- - **Default**: `bundle`
220
+ - **Default**: `'bundle'`
221
221
 
222
222
  ## copy
223
223
 
@@ -346,15 +346,37 @@ When this configuration is disabled, there is no guarantee that the type files w
346
346
  The output path of the dts file, based on [outDir](/api/config/build-config#outDir)
347
347
 
348
348
  - **Type**: `string`
349
- - **Default**: `. /types`
349
+ - **Default**: `./`
350
+
351
+ For example, output to the `types` directory under the `outDir`:
352
+
353
+ ```js modern.config.ts
354
+ export default defineConfig({
355
+ buildConfig: {
356
+ dts: {
357
+ distPath: './types',
358
+ },
359
+ },
360
+ });
361
+ ```
350
362
 
351
363
  ## dts.only
352
364
 
353
- Generate only dts files, not js files
365
+ Whether to generate only type files during the build process without generating JavaScript output files.
354
366
 
355
367
  - **Type**: `boolean`
356
368
  - **Default**: `false`
357
369
 
370
+ ```js modern.config.ts
371
+ export default defineConfig({
372
+ buildConfig: {
373
+ dts: {
374
+ only: true,
375
+ },
376
+ },
377
+ });
378
+ ```
379
+
358
380
  ## dts.respectExternal
359
381
 
360
382
  When set to `false`, the type of third-party packages will be excluded from the bundle, when set to `true`, it will determine whether third-party types need to be bundled based on [externals](#externals).
@@ -365,6 +387,16 @@ So we can avoid it with this configuration.
365
387
  - **Type**: `boolean`
366
388
  - **Default**: `true`
367
389
 
390
+ ```js modern.config.ts
391
+ export default defineConfig({
392
+ buildConfig: {
393
+ dts: {
394
+ respectExternal: false,
395
+ },
396
+ },
397
+ });
398
+ ```
399
+
368
400
  ## dts.tsconfigPath
369
401
 
370
402
  Path to the tsconfig file
@@ -372,11 +404,22 @@ Path to the tsconfig file
372
404
  - **Type**: `string`
373
405
  - **Default**: `. /tsconfig.json`
374
406
 
407
+ ```js modern.config.ts
408
+ export default defineConfig({
409
+ buildConfig: {
410
+ dts: {
411
+ tsconfigPath: './other-tsconfig.json',
412
+ },
413
+ },
414
+ });
415
+ ```
416
+
375
417
  ## esbuildOptions
376
418
 
377
419
  Used to modify the [esbuild configuration](https://esbuild.github.io/api/).
378
420
 
379
421
  - **Type**: `Function`
422
+ - **Build Type**: `Only supported for buildType: 'bundle'`
380
423
  - **Default**: `c => c`
381
424
 
382
425
  For example, if we need to modify the file extension of the generated files:
@@ -645,17 +688,33 @@ export default {
645
688
 
646
689
  ## outDir
647
690
 
648
- Specifies the output directory of the build
691
+ Specifies the output directory of the build.
649
692
 
650
693
  - **Type**: `string`
651
- - **Default**: `dist`
694
+ - **Default**: `./dist`
695
+
696
+ ```js modern.config.ts
697
+ export default defineConfig({
698
+ buildConfig: {
699
+ outDir: './dist/esm',
700
+ },
701
+ });
702
+ ```
652
703
 
653
704
  ## platform
654
705
 
655
706
  Generates code for the node environment by default, you can also specify `browser` which will generate code for the browser environment
656
707
 
657
708
  - **Type**: `'browser' | 'node'`
658
- - **Default**: `node`
709
+ - **Default**: `'node'`
710
+
711
+ ```js modern.config.ts
712
+ export default defineConfig({
713
+ buildConfig: {
714
+ platform: 'browser',
715
+ },
716
+ });
717
+ ```
659
718
 
660
719
  ## redirect
661
720
 
@@ -886,12 +945,38 @@ export default {
886
945
 
887
946
  ## style.postcss
888
947
 
889
- - plugins
890
- - processOptions
948
+ Used to configure options for PostCSS. The provided values will be merged with the default configuration using `Object.assign`. Note that `Object.assign` performs a shallow copy, so it will completely override the built-in `plugins` array.
949
+
950
+ For detailed configuration, please refer to [PostCSS](https://github.com/postcss/postcss#options).
951
+
952
+ - **Type**:
953
+
954
+ ```ts
955
+ type PostcssOptions = {
956
+ processOptions?: ProcessOptions;
957
+ plugins?: AcceptedPlugin[];
958
+ };
959
+ ```
960
+
961
+ - **Default**:
891
962
 
892
- See [PostCSS](https://github.com/postcss/postcss#options) for detailed configuration
963
+ ```ts
964
+ const defaultConfig = {
965
+ plugins: [
966
+ // The following plugins are enabled by default
967
+ require('postcss-flexbugs-fixes'),
968
+ require('postcss-media-minmax'),
969
+ require('postcss-nesting'),
970
+ // The following plugins are only enabled when the target is `es5`
971
+ require('postcss-custom-properties'),
972
+ require('postcss-initial'),
973
+ require('postcss-page-break'),
974
+ require('postcss-font-variant'),
975
+ ],
976
+ };
977
+ ```
893
978
 
894
- **Basic usage:**
979
+ - **Example**:
895
980
 
896
981
  ```js modern.config.ts
897
982
  export default defineConfig({
@@ -1021,6 +1106,7 @@ const tailwind = {
1021
1106
  ],
1022
1107
  };
1023
1108
  ```
1109
+
1024
1110
  </details>
1025
1111
 
1026
1112
  When the value is of type `object`, it is merged with the default configuration via `Object.assign`.
@@ -100,6 +100,7 @@ export const buildConfig = [
100
100
  {
101
101
  format: 'umd',
102
102
  target: 'es6',
103
+ platform: 'browser',
103
104
  buildType: 'bundle',
104
105
  outDir: './dist/umd',
105
106
  },
@@ -183,6 +184,7 @@ export const buildConfig = [
183
184
  {
184
185
  format: 'umd',
185
186
  target: 'es6',
187
+ platform: 'browser',
186
188
  buildType: 'bundle',
187
189
  outDir: './dist/umd',
188
190
  },
@@ -6,7 +6,7 @@ sidebar_position: 3
6
6
 
7
7
  ## 3 minute demo
8
8
 
9
- Want to experience Module Tools in action? The only prerequisite you need is [Node.js LTS](https://github.com/nodejs/Release) and make sure your Node version is **>= 14.18.0**.We recommend using the LTS version of Node.js 16.
9
+ Want to experience Module Tools in action? The only prerequisite you need is [Node.js LTS](https://github.com/nodejs/Release) and make sure your Node version is **>= 14.18.0**.We recommend using the LTS version of Node.js 18.
10
10
 
11
11
  ### Create new project
12
12
 
@@ -73,6 +73,25 @@ Finally, add the command `"build": "modern build"` to the project's `package.jso
73
73
 
74
74
  If your project has a `src/index.(js|jsx)` file or both `src/index.(ts|tsx)` and `tsconfig.json` files, then congratulations you can run the `npm run build` command directly to build your project with Module Tools.
75
75
 
76
+ ### Core npm Package
77
+
78
+ `@modern-js/module-tools` is the core npm package of Module Tools, providing the following capabilities:
79
+
80
+ - It offers commonly used CLI commands such as `modern dev`, `modern build`, and more.
81
+ - It integrates Modern.js Core, providing capabilities for configuration parsing, plugin loading, and more.
82
+ - It integrates esbuild and SWC, providing build capabilities.
83
+ - It integrates some commonly used plugins, such as `plugin-lint`, `plugin-changeset`, and others.
84
+
85
+ `@modern-js/module-tools` is implemented based on the plugin system of Modern.js. Essentially, it is a plugin. Therefore, you need to register `moduleTools` in the `plugins` field of the configuration file:
86
+
87
+ ```ts modern.config.ts
88
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
89
+
90
+ export default defineConfig({
91
+ plugins: [moduleTools()],
92
+ });
93
+ ```
94
+
76
95
  ### View official example
77
96
 
78
97
  **If you want to see the complete project using the modular engineering scheme, you can execute the following command**.
@@ -218,7 +218,7 @@ export default defineConfig({
218
218
  构建类型,`bundle` 会打包你的代码,`bundleless` 只做代码的转换。
219
219
 
220
220
  - 类型: `'bundle' | 'bundleless'`
221
- - 默认值: `bundle`
221
+ - 默认值: `'bundle'`
222
222
 
223
223
  ## copy
224
224
 
@@ -345,16 +345,38 @@ export default defineConfig({
345
345
 
346
346
  类型文件的输出路径,基于 [outDir](/api/config/build-config#outDir) 进行输出。
347
347
 
348
- - 类型: `string`
349
- - 默认值: `./types`
348
+ - 类型: `string`
349
+ - 默认值: `./`
350
+
351
+ 比如输出到 `outDir` 下面的 `types` 目录:
352
+
353
+ ```js modern.config.ts
354
+ export default defineConfig({
355
+ buildConfig: {
356
+ dts: {
357
+ distPath: './types',
358
+ },
359
+ },
360
+ });
361
+ ```
350
362
 
351
363
  ## dts.only
352
364
 
353
- 只生成类型文件,不生成 js 文件。
365
+ 是否在构建时只生成类型文件,不生成 JavaScript 产物文件。
354
366
 
355
367
  - 类型: `boolean`
356
368
  - 默认值: `false`
357
369
 
370
+ ```js modern.config.ts
371
+ export default defineConfig({
372
+ buildConfig: {
373
+ dts: {
374
+ only: true,
375
+ },
376
+ },
377
+ });
378
+ ```
379
+
358
380
  ## dts.respectExternal
359
381
 
360
382
  当设为 `false` 时,不会打包任何三方包类型,设为 `true` 时,会根据 [externals](#externals) 来决定是否需要打包三方类型。
@@ -364,6 +386,16 @@ export default defineConfig({
364
386
  - 类型: `boolean`
365
387
  - 默认值: `true`
366
388
 
389
+ ```js modern.config.ts
390
+ export default defineConfig({
391
+ buildConfig: {
392
+ dts: {
393
+ respectExternal: false,
394
+ },
395
+ },
396
+ });
397
+ ```
398
+
367
399
  ## dts.tsconfigPath
368
400
 
369
401
  TypeScript 配置文件的路径。
@@ -371,12 +403,22 @@ TypeScript 配置文件的路径。
371
403
  - 类型: `string`
372
404
  - 默认值: `./tsconfig.json`
373
405
 
406
+ ```js modern.config.ts
407
+ export default defineConfig({
408
+ buildConfig: {
409
+ dts: {
410
+ tsconfigPath: './other-tsconfig.json',
411
+ },
412
+ },
413
+ });
414
+ ```
415
+
374
416
  ## esbuildOptions
375
417
 
376
418
  用于修改底层的 [esbuild 配置](https://esbuild.github.io/api/)。
377
419
 
378
- - 类型: `Function`
379
- - 默认值: `c => c`
420
+ - 类型: `Function`
421
+ - 默认值: `c => c`
380
422
 
381
423
  例如,我们需要修改生成文件的后缀:
382
424
 
@@ -645,17 +687,33 @@ export default defineConfig({
645
687
 
646
688
  ## outDir
647
689
 
648
- 指定构建的输出目录
690
+ 指定构建的输出目录。
649
691
 
650
- - 类型: `string`
651
- - 默认值: `dist`
692
+ - 类型: `string`
693
+ - 默认值: `./dist`
694
+
695
+ ```js modern.config.ts
696
+ export default defineConfig({
697
+ buildConfig: {
698
+ outDir: './dist/esm',
699
+ },
700
+ });
701
+ ```
652
702
 
653
703
  ## platform
654
704
 
655
705
  默认生成用于 Node.js 环境下的代码,你也可以指定为 `browser`,会生成用于浏览器环境的代码。
656
706
 
657
707
  - 类型: `'browser' | 'node'`
658
- - 默认值: `node`
708
+ - 默认值: `'node'`
709
+
710
+ ```js modern.config.ts
711
+ export default defineConfig({
712
+ buildConfig: {
713
+ platform: 'browser',
714
+ },
715
+ });
716
+ ```
659
717
 
660
718
  ## redirect
661
719
 
@@ -887,12 +945,38 @@ export default defineConfig({
887
945
 
888
946
  ## style.postcss
889
947
 
890
- - plugins
891
- - processOptions
948
+ 用于配置 PostCSS 的选项,传入的值会与默认配置通过 `Object.assign` 合并。注意 `Object.assign` 是浅拷贝,因此会完全覆盖内置的 plugins 数组。
892
949
 
893
- 详细配置查看 [PostCSS](https://github.com/postcss/postcss#options)。
950
+ 详细配置请查看 [PostCSS](https://github.com/postcss/postcss#options)。
894
951
 
895
- **基础使用:**
952
+ - 类型:
953
+
954
+ ```ts
955
+ type PostcssOptions = {
956
+ processOptions?: ProcessOptions;
957
+ plugins?: AcceptedPlugin[];
958
+ };
959
+ ```
960
+
961
+ - 默认值:
962
+
963
+ ```ts
964
+ const defaultConfig = {
965
+ plugins: [
966
+ // 以下插件默认启用
967
+ require('postcss-flexbugs-fixes'),
968
+ require('postcss-media-minmax'),
969
+ require('postcss-nesting'),
970
+ // 以下插件仅在 target 为 `es5` 时启用
971
+ require('postcss-custom-properties'),
972
+ require('postcss-initial'),
973
+ require('postcss-page-break'),
974
+ require('postcss-font-variant'),
975
+ ],
976
+ };
977
+ ```
978
+
979
+ - 示例:
896
980
 
897
981
  ```js modern.config.ts
898
982
  export default defineConfig({
@@ -1024,6 +1108,7 @@ const tailwind = {
1024
1108
  ],
1025
1109
  };
1026
1110
  ```
1111
+
1027
1112
  </details>
1028
1113
 
1029
1114
  值为 `object` 类型时,与默认配置通过 `Object.assign` 合并。
@@ -100,6 +100,7 @@ export const buildConfig = [
100
100
  {
101
101
  format: 'umd',
102
102
  target: 'es6',
103
+ platform: 'browser',
103
104
  buildType: 'bundle',
104
105
  outDir: './dist/umd',
105
106
  },
@@ -183,6 +184,7 @@ export const buildConfig = [
183
184
  {
184
185
  format: 'umd',
185
186
  target: 'es6',
187
+ platform: 'browser',
186
188
  buildType: 'bundle',
187
189
  outDir: './dist/umd',
188
190
  },
@@ -6,7 +6,7 @@ sidebar_position: 3
6
6
 
7
7
  ## 三分钟快速上手
8
8
 
9
- 想要实际体验 Module Tools?首先需要安装 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **14.18.0**。我们推荐使用 Node.js 16 的 LTS 版本。
9
+ 想要实际体验 Module Tools?首先需要安装 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **14.18.0**。我们推荐使用 Node.js 18 的 LTS 版本。
10
10
 
11
11
  ### 创建新项目
12
12
 
@@ -70,6 +70,25 @@ export default defineConfig({
70
70
 
71
71
  如果你的项目存在 `src/index.(js|jsx)` 文件或者同时存在 `src/index.(ts|tsx)` 和 `tsconfig.json` 文件,那么恭喜你可以运行直接运行 `npm run build` 来使用 Module Tools 构建你的项目了。
72
72
 
73
+ ### 核心 npm 包
74
+
75
+ `@modern-js/module-tools` 是 Module Tools 的核心 npm 包,主要提供以下能力:
76
+
77
+ - 提供 `modern dev`, `modern build` 等常用的 CLI 命令。
78
+ - 集成 Modern.js Core,提供配置解析、插件加载等能力。
79
+ - 集成 esbuild 和 SWC,提供构建能力。
80
+ - 集成一些最为常用的插件,比如 `plugin-lint`、`plugin-changeset` 等。
81
+
82
+ `@modern-js/module-tools` 是基于 Modern.js 的插件体系实现的,本质上是一个插件,因此你需要在配置文件的 `plugins` 字段中注册 `moduleTools`:
83
+
84
+ ```ts modern.config.ts
85
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
86
+
87
+ export default defineConfig({
88
+ plugins: [moduleTools()],
89
+ });
90
+ ```
91
+
73
92
  ### 查看官方示例
74
93
 
75
94
  **如果你想要看看使用了模块工程方案的完整项目,可以执行以下命令**:
package/package.json CHANGED
@@ -9,15 +9,15 @@
9
9
  "directory": "packages/document/module-doc"
10
10
  },
11
11
  "license": "MIT",
12
- "version": "2.28.0",
12
+ "version": "2.30.0",
13
13
  "main": "index.js",
14
14
  "dependencies": {
15
15
  "@code-hike/mdx": "^0.7.4",
16
16
  "react": "^18.2.0",
17
17
  "react-dom": "^18.2.0",
18
18
  "shiki": "^0.11.1",
19
- "@modern-js/doc-plugin-auto-sidebar": "2.28.0",
20
- "@modern-js/doc-tools": "2.28.0"
19
+ "@modern-js/doc-plugin-auto-sidebar": "2.30.0",
20
+ "@modern-js/doc-tools": "2.30.0"
21
21
  },
22
22
  "scripts": {
23
23
  "dev": "modern dev",