Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

docs: make the description of optimization.minimizer more clear #640

Merged
merged 3 commits into from
Mar 18, 2024
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
33 changes: 31 additions & 2 deletions docs/en/config/optimization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,17 @@ If you are encountering performance issue, and you are using `optimization.split

<PropertyType
type="Array<Plugin>"
defaultValueList={[{ defaultValue: '[]' }]}
defaultValueList={[
{
defaultValue:
'[new SwcJsMinimizerRspackPlugin(), new SwcCssMinimizerRspackPlugin()]',
},
]}
/>

Customize the minimizer. When using a custom minimizer, the built-in minimizer will be disabled.
Customize the minimizer. By default, [`rspack.SwcJsMinimizerRspackPlugin`](/config/plugins.html#swcjsminimizerrspackplugin)
and [`rspack.SwcCssMinimizerRspackPlugin`](/config/plugins.html#swccssminimizerrspackplugin) are used.
When `optimization.minimizer` is specified, the default minimizers will be disabled.

```js title=rspack.config.js
const minifyPlugin = require('@rspack/plugin-minify');
Expand All @@ -99,6 +106,28 @@ module.exports = {
};
```

Use the built-in minimizer with custom options:

```js title=rspack.config.js
const rspack = require('@rspack/core');
module.exports = {
// ...
optimization: {
minimize: process.env.NODE_ENV === 'production',
// when `optimization.minimizer` is specified, the default minimizers are disabled by default
// but you can use '...', it represents the default minimizers
minimizer: [
new rspack.SwcJsMinimizerRspackPlugin({
format: {
comments: false,
},
}),
new rspack.SwcCssMinimizerRspackPlugin(),
],
},
};
```

## optimization.removeEmptyChunks

<PropertyType type="boolean" defaultValueList={[{ defaultValue: 'true' }]} />
Expand Down
4 changes: 2 additions & 2 deletions docs/en/config/plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ For complex HTML configuration requirements, you can use [html-webpack-plugin](h

<ApiMeta addedVersion={'0.3.3'} />

This plugin can be used to compress JS assets.
This plugin can be used to compress JS assets. See [optimization.minimizer](/config/optimization.html#optimizationminimizer).

```js
new rspack.SwcJsMinimizerRspackPlugin(options);
Expand Down Expand Up @@ -1032,7 +1032,7 @@ new rspack.SwcJsMinimizerRspackPlugin(options);

<ApiMeta addedVersion={'0.3.3'} />

This plugin can be used to compress CSS assets.
This plugin can be used to compress CSS assets. See [optimization.minimizer](/config/optimization.html#optimizationminimizer).

```js
new rspack.SwcCssMinimizerRspackPlugin();
Expand Down
32 changes: 30 additions & 2 deletions docs/zh/config/optimization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ EntryChunk2(index.js, a.js, b.js)

<PropertyType.CN
type="Array<Plugin>"
defaultValueList={[{ defaultValue: '[]' }]}
defaultValueList={[
{
defaultValue:
'[new SwcJsMinimizerRspackPlugin(), new SwcCssMinimizerRspackPlugin()]',
},
]}
/>

自定义压缩器。当使用自定义压缩器时,内置压缩器将会被禁用。
自定义压缩器。默认使用 [`rspack.SwcJsMinimizerRspackPlugin`](/config/plugins.html#swcjsminimizerrspackplugin)
和 [`rspack.SwcCssMinimizerRspackPlugin`](/config/plugins.html#swccssminimizerrspackplugin)。当声明了 `optimization.minimizer`,默认压缩器会被禁用。

```js title=rspack.config.js
const minifyPlugin = require('@rspack/plugin-minify');
Expand All @@ -99,6 +105,28 @@ module.exports = {
};
```

使用内置压缩器和自定义选项:

```js title=rspack.config.js
const rspack = require('@rspack/core');
module.exports = {
// ...
optimization: {
minimize: process.env.NODE_ENV === 'production',
// 当声明了 `optimization.minimizer`,默认压缩器会被禁用
// 但你可以配合使用 '...',它代表默认压缩器
minimizer: [
new rspack.SwcJsMinimizerRspackPlugin({
format: {
comments: false,
},
}),
new rspack.SwcCssMinimizerRspackPlugin(),
],
},
};
```

## optimization.removeEmptyChunks

<PropertyType.CN type="boolean" defaultValueList={[{ defaultValue: 'true' }]} />
Expand Down
4 changes: 2 additions & 2 deletions docs/zh/config/plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ new rspack.HtmlRspackPlugin(options);

<ApiMeta addedVersion={'0.3.3'} />

此插件可以用来压缩 JS 产物。
此插件可以用来压缩 JS 产物。参见 [optimization.minimizer](/config/optimization.html#optimizationminimizer)。

```js
new rspack.SwcJsMinimizerRspackPlugin(options);
Expand Down Expand Up @@ -1029,7 +1029,7 @@ new rspack.SwcJsMinimizerRspackPlugin(options);

<ApiMeta addedVersion={'0.3.3'} />

此插件可以用来压缩 CSS 产物。
此插件可以用来压缩 CSS 产物。参见 [optimization.minimizer](/config/optimization.html#optimizationminimizer)。

```js
new rspack.SwcCssMinimizerRspackPlugin();
Expand Down
1 change: 1 addition & 0 deletions project-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ statoscope
suxin2017
svgr
swccssminimizerplugin
swccssminimizerrspackplugin
swcjsminimizerplugin
swcjsminimizerrspackplugin
swcpack
Expand Down
Loading