Skip to content

Commit

Permalink
fix: lightningCss default target use browserslist set
Browse files Browse the repository at this point in the history
  • Loading branch information
noshower committed Sep 11, 2024
1 parent b1bf153 commit 4abb856
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
BuiltinPluginName,
type RawLightningCssMinimizerRspackPluginOptions
} from "@rspack/binding";
import browserslist from 'browserslist';

import {
type Drafts,
Expand Down Expand Up @@ -37,7 +38,7 @@ export const LightningCssMinimizerRspackPlugin = create(
): RawLightningCssMinimizerRspackPluginOptions => {
const { include, exclude, draft, nonStandard, pseudoClasses } =
options?.minimizerOptions ?? {};
const targets = options?.minimizerOptions?.targets ?? "fully supports es6"; // last not support es module chrome version
const targets = options?.minimizerOptions?.targets ?? browserslist(null);
return {
test: options?.test,
include: options?.include,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Below are the configurations supported, `targets` configuration is plain browser

:::info

1. The default `targets` is set to `"fully supports es6"` to ensure that minification does not introduce advanced syntax that could cause browser incompatibility (minification might turn lower-level syntax into advanced syntax because it is shorter).
1. The default `targets` are configured using [browserslist](https://github.com/browserslist/browserslist) . If configuration is not found, browserslist will use defaults: `> 0.5%, last 2 versions, Firefox ESR, not dead`
2. The `exclude` option is configured with all features by default. We usually do syntax degradation in [builtin:lightningcss-loader](/guide/features/builtin-lightningcss-loader) or other loaders, so this plugin excludes all features by default to avoid syntax downgrading during the minimize process.

We recommend and encourage users to configure their own `targets` to achieve the best minification results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ document.body.className = styles.a;

:::info

1. 默认 `targets` `"fully supports es6"`,以保证压缩后不会出现高级语法导致浏览器不兼容(压缩过程中可能会出现由于高级语法更短而将低级语法转为高级语法)
1. 默认 `targets` 是通过 [browserslist](https://github.com/browserslist/browserslist) 配置的。如果没有找到配置,browserslist 会使用默认值: `> 0.5%, last 2 versions, Firefox ESR, not dead`
2. `exclude` 选项默认配置了所有的 features。我们通常会在[builtin:lightningcss-loader](/guide/features/builtin-lightningcss-loader) 或其他 loaders 中进行语法降级,所以此插件默认 exclude 所有的 features,避免在 minimize 过程中进行语法降级。

我们建议并鼓励用户配置自己所需的 `targets`,以获得最好的压缩效果。
Expand Down

0 comments on commit 4abb856

Please sign in to comment.