Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions docs/config/compilation-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Targeting `browser`:
* **`browser-es2017`**: Compiling the project to browsers that support `async await` natively.
* **`browser-es2015`**: Compiling the project to browsers that support `es6 features` natively.
* **`browser-legacy`**: Compile the project to `ES5`, for example, `IE9`. Note that this may introduce lots of polyfills which makes production size larger. Make sure you really need to support legacy browsers like `IE9`.
* **`browser-esnext`**: Compile the project to latest modern browsers, no polyfill will be injected.
* **`browser-esnext`**: Compile the project to latest modern browsers, no polyfill will be injected.
* **`browser`**: Alias of `browser-es2017`

Targeting `node`:
Expand Down Expand Up @@ -264,6 +264,7 @@ export default defineConfig({
### external

- **default**: `[]`
- **type**: `(string | Record<string, string>)[]`

Configure the imports that are external, and the imports that are external will not appear in the compiled product. However, the corresponding import statement will not be deleted. You need to customize how to deal with external, otherwise an error will be reported at runtime. If targetEnv is an external module under node, it will automatically try to require the module.

Expand All @@ -272,7 +273,7 @@ It needs to be configured in a regular way, for example:
```ts
export default defineConfig({
compilation: {
external: ["^stream$"],
external: ["^stream$", { jquery: "Jquery" }],
},
});
```
Expand Down Expand Up @@ -698,6 +699,43 @@ type MinifyOptions = boolean | {
```
The `compress` and `mangle` options is the same as [swc's minify config](https://swc.rs/docs/configuration/minification).

#### `minify.compress`

- **default**: `{}`
- **type**: [`TerserCompressOptions`](https://swc.rs/docs/configuration/minification#jscminifycompress)

compress option

#### `minify.mangle`

- **default**: `{}`
- **type**: [`TerserMangleOptions`](https://swc.rs/docs/configuration/minification#jscminifymangle)

compress variable parameters

#### `minify.include`

- **default**: `[]`
- **type**: `string[]`

contains modules that need to be compressed, defaults to all, only takes effect when `minify.mode` is `minify-module`.

#### `minify.exclude`

- **default**: `["*.min.js"]`
- **type**: `string[]`

exclude unnecessary compression modules, only takes effect when `minify.mode` is `minify-module`.

#### `minify.mode`

- **default**: `'minify-module'`
- **type**: `'minify-module' | 'minify-resource-pot'`

`minify-module` module level `minify`, you can control which modules need to be minified through parameters, the compression is more refined and the efficiency is better

`minify-resource-pot` `ResourcePot` level `minify`, specific modules cannot be controlled through parameters

### presetEnv

- **default**: `false` in development mode, `true` in build mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export default defineConfig({
### external

- **默认值**: `[]`
- **类型**: `(string | Record<string, string>)[]`

配置被 external 的导入,被 external 的导入不会出现在编译产物中。但是对应 import 语句不会删除,需要自定义 external 后如何处理,否则运行时会报错,对于 targetEnv 是 node 下的 external 模块,会自动尝试 require 该模块。

Expand All @@ -272,7 +273,7 @@ export default defineConfig({
```ts
export default defineConfig({
compilation: {
external: ["^stream$"],
external: ["^stream$", { jquery: "Jquery" }],
},
});
```
Expand Down Expand Up @@ -688,9 +689,47 @@ Default to `0.8`, immutable module will have 80% request numbers. For example, i
### minify

- **默认值**: 在开发模式是 `false`,构建模式是 `true`
- **类型**: `bool | JsMinifyOptions`

是否启用压缩,开启后将会对产物进行压缩和混淆。参考 [压缩](/docs/advanced/tree-shake)。

#### `minify.compress`

- **默认值**: `{}`
- **类型**: [`TerserCompressOptions`](https://swc.rs/docs/configuration/minification#jscminifycompress)

压缩参数

#### `minify.mangle`

- **默认值**: `{}`
- **类型**: [`TerserMangleOptions`](https://swc.rs/docs/configuration/minification#jscminifymangle)

压缩变量参数

#### `minify.include`

- **默认值**: `[]`
- **类型**: `string[]`

包含需要压缩的模块,默认全部,仅在 `minify.mode` 为 `minify-module` 生效

#### `minify.exclude`

- **默认值**: `["*.min.(js|css|html)"]`
- **类型**: `string[]`

排除不需要压缩模块,仅在 `minify.mode` 为 `minify-module` 生效

#### `minify.mode`

- **默认值**: `'minify-module'`
- **类型**: `'minify-module' | 'minify-resource-pot'`

`minify-module` 模块级别 `minify`,可以通过参数控制需要 minify 哪些模块,压缩的更为精细,效率更好

`minify-resource-pot` `ResourcePot` 级别 `minify`,无法通过参数控制具体的模块

### presetEnv

- **默认值**: 在开发模式是 `false`,构建模式是 `true`
Expand Down