Skip to content

Commit 91059e4

Browse files
authored
docs: deprecate addIncludes/addExcludes utils (web-infra-dev#5034)
1 parent 5d09f4a commit 91059e4

File tree

6 files changed

+22
-152
lines changed

6 files changed

+22
-152
lines changed

packages/document/builder-doc/docs/en/config/tools/babel.md

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Please note the limitations of `tools.babel` in the following usage scenarios:
1212

1313
### Function Type
1414

15-
1615
When `tools.babel` is of type `Function`, the default Babel configuration will be passed as the first parameter. You can directly modify the configuration object or return an object as the final `babel-loader` configuration.
1716

1817
```js
@@ -144,50 +143,6 @@ export default {
144143
};
145144
```
146145

147-
#### addIncludes
148-
149-
- **Type:** `(includes: string | RegExp | (string | RegExp)[]) => void`
150-
151-
By default, Babel will only compile the application code in the src directory. With `addIncludes` you can specify that Babel compile some files in node_modules. For example:
152-
153-
```js
154-
export default {
155-
tools: {
156-
babel(config, { addIncludes }) {
157-
addIncludes(/\/node_modules\/query-string\//);
158-
},
159-
},
160-
};
161-
```
162-
163-
:::tip
164-
The usage of the `addIncludes` function is identical to the `source.include` configuration option. We recommend using `source.include` instead of `addIncludes` because `source.include` has a wider range of use cases. For example, when migrating from Babel to SWC compilation, `source.include` can still work, while the `addIncludes` function will not be effective.
165-
166-
Please refer to the [source.include documentation](https://modernjs.dev/builder/en/api/config-source.html#sourceinclude) for more detailed usage.
167-
:::
168-
169-
#### addExcludes
170-
171-
- **Type:** `(excludes: string | RegExp | (string | RegExp)[]) => void`
172-
173-
Contrary to `addIncludes`, specifies that certain files are excluded from Babel's compilation.
174-
175-
For example, without compiling files in the `src/example` directory:
176-
177-
```js
178-
export default {
179-
tools: {
180-
babel(config, { addExcludes }) {
181-
addExcludes('src/example');
182-
},
183-
},
184-
};
185-
```
186-
187-
:::tip
188-
The usage of the `addExcludes` function is basically the same as the `source.exclude` config, please see the [source.exclude documentation](https://modernjs.dev/builder/api/config-source.html#sourceexclude) for a more detailed usage. You can also use `source.exclude` directly instead of the `addExcludes` function.
189-
:::
190-
191146
#### modifyPresetEnvOptions
192147

193148
- **Type:** `(options: PresetEnvOptions) => void`
@@ -226,6 +181,14 @@ export default {
226181
};
227182
```
228183

184+
#### addIncludes
185+
186+
Deprecated, please use [source.include](https://modernjs.dev/en/configure/app/source/include.html) instead, both have the same functionality.
187+
188+
#### addExcludes
189+
190+
Deprecated, please use [source.exclude](https://modernjs.dev/en/configure/app/source/exclude.html) instead, both have the same functionality.
191+
229192
### Debugging Babel Configuration
230193

231194
After modifying the `babel-loader` configuration through `tools.babel`, you can view the final generated configuration in [Builder debug mode](https://modernjs.dev/builder/en/guide/debug/debug-mode.html).

packages/document/builder-doc/docs/en/config/tools/tsLoader.md

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,38 +49,10 @@ export default {
4949

5050
### Util Functions
5151

52-
When the value of `tools.tsLoader` is a Function, the utils functions available for the second parameter are as follows:
53-
5452
#### addIncludes
5553

56-
- **Type:** `(includes: string | RegExp | Array<string | RegExp>) => void`
57-
58-
By default, only the application code in the src directory will be compiled. Use `addIncludes` to specify ts-loader to compile some files under `node_modules`. For example:
59-
60-
```ts
61-
export default {
62-
tools: {
63-
tsLoader: (config, { addIncludes }) => {
64-
addIncludes([/node_modules\/react/]);
65-
},
66-
},
67-
};
68-
```
54+
Deprecated, please use [source.include](https://modernjs.dev/en/configure/app/source/include.html) instead, both have the same functionality.
6955

7056
#### addExcludes
7157

72-
- **Type:** `(excludes: string | RegExp | Array<string | RegExp>) => void`
73-
74-
Contrary to `addIncludes`, specify `ts-loader` to exclude certain files when compiling.
75-
76-
For example, without compiling files in the `src/example` directory:
77-
78-
```ts
79-
export default {
80-
tools: {
81-
tsLoader: (config, { addExcludes }) => {
82-
addExcludes([/src\/example\//]);
83-
},
84-
},
85-
};
86-
```
58+
Deprecated, please use [source.exclude](https://modernjs.dev/en/configure/app/source/exclude.html) instead, both have the same functionality.

packages/document/builder-doc/docs/zh/config/tools/babel.md

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -142,51 +142,6 @@ export default {
142142
};
143143
```
144144

145-
#### addIncludes
146-
147-
- **类型:** `(includes: string | RegExp | (string | RegExp)[]) => void`
148-
149-
默认情况下 Babel 只会编译 src 目录下的业务代码,使用 `addIncludes` 你可以指定 Babel 编译 node_modules 下的一些文件。比如编译 `query-string` 依赖:
150-
151-
```js
152-
export default {
153-
tools: {
154-
babel(config, { addIncludes }) {
155-
addIncludes(/\/node_modules\/query-string\//);
156-
},
157-
},
158-
};
159-
```
160-
161-
:::tip
162-
`addIncludes` 函数的用法与 `source.include` 配置项完全一致,我们建议直接使用 `source.include` 来代替它,因为 `source.include` 的使用场景更广。比如,当你从 Babel 迁移切换到 SWC 编译时,`source.include` 仍然可以生效,而 `addIncludes` 函数则无法生效。
163-
164-
请查看 [「source.include 文档」](https://modernjs.dev/builder/api/config-source.html#sourceinclude) 来查看更详细的用法说明。
165-
166-
:::
167-
168-
#### addExcludes
169-
170-
- **类型:** `(excludes: string | RegExp | (string | RegExp)[]) => void`
171-
172-
`addExcludes``addIncludes` 的用处相反,指定 Babel 编译时排除某些文件。
173-
174-
比如不编译 `src/example` 目录下的文件:
175-
176-
```js
177-
export default {
178-
tools: {
179-
babel(config, { addExcludes }) {
180-
addExcludes('src/example');
181-
},
182-
},
183-
};
184-
```
185-
186-
:::tip
187-
`addExcludes` 函数的用法与 `source.exclude` 配置项基本一致,请查看 [source.exclude 文档](https://modernjs.dev/builder/api/config-source.html#sourceexclude) 来查看更详细的用法说明。也可以直接使用 `source.exclude` 来代替 `addExcludes` 函数。
188-
:::
189-
190145
#### modifyPresetEnvOptions
191146

192147
- **类型:** `(options: PresetEnvOptions) => void`
@@ -225,6 +180,14 @@ export default {
225180
};
226181
```
227182

183+
#### addIncludes
184+
185+
已废弃,请使用 [source.include](https://modernjs.dev/configure/app/source/include.html) 代替,两者功能完全一致。
186+
187+
#### addExcludes
188+
189+
已废弃,请使用 [source.exclude](https://modernjs.dev/configure/app/source/exclude.html) 代替,两者功能完全一致。
190+
228191
### 调试 Babel 配置
229192

230193
当你通过 `tools.babel` 修改 `babel-loader` 配置后,可以在 [Builder 调试模式](https://modernjs.dev/builder/guide/debug/debug-mode.html) 下查看最终生成的配置。

packages/document/builder-doc/docs/zh/config/tools/tsLoader.md

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,38 +49,10 @@ export default {
4949

5050
### 工具函数
5151

52-
`tools.tsLoader` 的值为 Function 类型时,第二个参数可用的工具函数如下:
53-
5452
#### addIncludes
5553

56-
- **类型:** `(includes: string | RegExp | Array<string | RegExp>) => void`
57-
58-
默认情况下只会编译 src 目录下的业务代码,使用 addIncludes 可以指定 ts-loader 编译 `node_modules` 下的一些文件。比如:
59-
60-
```ts
61-
export default {
62-
tools: {
63-
tsLoader: (config, { addIncludes }) => {
64-
addIncludes([/node_modules\/react/]);
65-
},
66-
},
67-
};
68-
```
54+
已废弃,请使用 [source.include](https://modernjs.dev/configure/app/source/include.html) 代替,两者功能完全一致。
6955

7056
#### addExcludes
7157

72-
- **类型:** `(excludes: string | RegExp | Array<string | RegExp>) => void`
73-
74-
`addIncludes` 相反,指定 `ts-loader` 编译时排除某些文件。
75-
76-
例如不编译 src/example 目录下的文件:
77-
78-
```ts
79-
export default {
80-
tools: {
81-
tsLoader: (config, { addExcludes }) => {
82-
addExcludes([/src\/example\//]);
83-
},
84-
},
85-
};
86-
```
58+
已废弃,请使用 [source.exclude](https://modernjs.dev/configure/app/source/exclude.html) 代替,两者功能完全一致。

packages/document/main-doc/docs/en/guides/troubleshooting/builder.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Solution:
209209

210210
If the compilation is succeed, but the `exports is not defined` error appears after opening the page, it is usually because a CommonJS module is compiled by Babel.
211211

212-
Under normal circumstances, Modern.js will not use Babel to compile CommonJS modules. If the [source.include](/en/configure/app/source/include.html) configuration option is used in the project, or the [tools.babel](/configure/app/tools/babel.html) `addIncludes` method, some CommonJS modules may be added to the Babel compilation.
212+
Under normal circumstances, Modern.js will not use Babel to compile CommonJS modules. If the [source.include](/en/configure/app/source/include.html) configuration option is used in the project, some CommonJS modules may be added to the Babel compilation.
213213

214214
There are two workarounds for this problem:
215215

packages/document/main-doc/docs/zh/guides/troubleshooting/builder.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ npm ls postcss
209209

210210
如果编译正常,但是打开页面后出现 `exports is not defined` 报错,通常是因为在项目中使用 Babel 编译了一个 CommonJS 模块,导致 Babel 出现异常。
211211

212-
在正常情况下,Modern.js 是不会使用 Babel 来编译 CommonJS 模块的。如果项目中使用了 [source.include](/configure/app/source/include.html) 配置项,或使用了 [tools.babel](/configure/app/tools/babel.html)`addIncludes` 方法,则可能会把一些 CommonJS 模块加入到 Babel 编译中。
212+
在正常情况下,Modern.js 是不会使用 Babel 来编译 CommonJS 模块的。如果项目中使用了 [source.include](/configure/app/source/include.html) 配置项,则可能会把一些 CommonJS 模块加入到 Babel 编译中。
213213

214214
该问题有两种解决方法:
215215

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy