Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lightningCss default target use browserslist set #7868

Closed
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
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no browserslist config, I think we should not change the default "fully supports es6". It is a potentially breaking change.

Copy link
Member

@chenjiahan chenjiahan Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we should resolve the browserslist config in the Rust side for better performance. Similar to #7544

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
Loading