@modern-js/module-tools-docs 2.29.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
|
@@ -945,12 +945,38 @@ export default {
|
|
|
945
945
|
|
|
946
946
|
## style.postcss
|
|
947
947
|
|
|
948
|
-
- plugins
|
|
949
|
-
- 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.
|
|
950
949
|
|
|
951
|
-
|
|
950
|
+
For detailed configuration, please refer to [PostCSS](https://github.com/postcss/postcss#options).
|
|
952
951
|
|
|
953
|
-
**
|
|
952
|
+
- **Type**:
|
|
953
|
+
|
|
954
|
+
```ts
|
|
955
|
+
type PostcssOptions = {
|
|
956
|
+
processOptions?: ProcessOptions;
|
|
957
|
+
plugins?: AcceptedPlugin[];
|
|
958
|
+
};
|
|
959
|
+
```
|
|
960
|
+
|
|
961
|
+
- **Default**:
|
|
962
|
+
|
|
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
|
+
```
|
|
978
|
+
|
|
979
|
+
- **Example**:
|
|
954
980
|
|
|
955
981
|
```js modern.config.ts
|
|
956
982
|
export default defineConfig({
|
|
@@ -1080,6 +1106,7 @@ const tailwind = {
|
|
|
1080
1106
|
],
|
|
1081
1107
|
};
|
|
1082
1108
|
```
|
|
1109
|
+
|
|
1083
1110
|
</details>
|
|
1084
1111
|
|
|
1085
1112
|
When the value is of type `object`, it is merged with the default configuration via `Object.assign`.
|
|
@@ -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
|
|
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**.
|
|
@@ -945,12 +945,38 @@ export default defineConfig({
|
|
|
945
945
|
|
|
946
946
|
## style.postcss
|
|
947
947
|
|
|
948
|
-
|
|
949
|
-
- processOptions
|
|
948
|
+
用于配置 PostCSS 的选项,传入的值会与默认配置通过 `Object.assign` 合并。注意 `Object.assign` 是浅拷贝,因此会完全覆盖内置的 plugins 数组。
|
|
950
949
|
|
|
951
|
-
|
|
950
|
+
详细配置请查看 [PostCSS](https://github.com/postcss/postcss#options)。
|
|
952
951
|
|
|
953
|
-
|
|
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
|
+
- 示例:
|
|
954
980
|
|
|
955
981
|
```js modern.config.ts
|
|
956
982
|
export default defineConfig({
|
|
@@ -1082,6 +1108,7 @@ const tailwind = {
|
|
|
1082
1108
|
],
|
|
1083
1109
|
};
|
|
1084
1110
|
```
|
|
1111
|
+
|
|
1085
1112
|
</details>
|
|
1086
1113
|
|
|
1087
1114
|
值为 `object` 类型时,与默认配置通过 `Object.assign` 合并。
|
|
@@ -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
|
|
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.
|
|
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.
|
|
20
|
-
"@modern-js/doc-tools": "2.
|
|
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",
|