Skip to content

Commit

Permalink
feat: enable lightningcss minify by default
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Jun 21, 2024
1 parent 7bb066e commit 7a87d5c
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 29 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/plugins/minimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const pluginMinimize = (): RsbuildPlugin => ({
return;
}

const { SwcJsMinimizerRspackPlugin, SwcCssMinimizerRspackPlugin } =
const { SwcJsMinimizerRspackPlugin, LightningCssMinimizerRspackPlugin } =
rspack;

const { minifyJs, minifyCss } = parseMinifyOptions(config);
Expand All @@ -130,7 +130,7 @@ export const pluginMinimize = (): RsbuildPlugin => ({
if (minifyCss) {
chain.optimization
.minimizer(CHAIN_ID.MINIMIZER.CSS)
.use(SwcCssMinimizerRspackPlugin, [])
.use(LightningCssMinimizerRspackPlugin, [])
.end();
}
});
Expand Down
13 changes: 10 additions & 3 deletions packages/core/tests/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,17 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
"affectedHooks": "compilation",
"name": "SwcJsMinimizerRspackPlugin",
},
SwcCssMinimizerRspackPlugin {
"_options": undefined,
LightningCssMinimizerRspackPlugin {
"_options": {
"browserslist": [
"defaults",
],
"errorRecovery": false,
"removeUnusedLocalIdents": true,
"unusedSymbols": [],
},
"affectedHooks": undefined,
"name": "SwcCssMinimizerRspackPlugin",
"name": "LightningCssMinimizerRspackPlugin",
},
],
"splitChunks": {
Expand Down
54 changes: 41 additions & 13 deletions packages/core/tests/minimize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ describe('plugin-minimize', () => {
"affectedHooks": "compilation",
"name": "SwcJsMinimizerRspackPlugin",
},
SwcCssMinimizerRspackPlugin {
"_options": undefined,
LightningCssMinimizerRspackPlugin {
"_options": {
"browserslist": [
"defaults",
],
"errorRecovery": false,
"removeUnusedLocalIdents": true,
"unusedSymbols": [],
},
"affectedHooks": undefined,
"name": "SwcCssMinimizerRspackPlugin",
"name": "LightningCssMinimizerRspackPlugin",
},
]
`,
Expand All @@ -76,7 +83,7 @@ describe('plugin-minimize', () => {

expect(bundlerConfigs[0].optimization?.minimizer?.length).toBe(1);
expect(bundlerConfigs[0].optimization?.minimizer?.[0]).toMatchObject({
name: 'SwcCssMinimizerRspackPlugin',
name: 'LightningCssMinimizerRspackPlugin',
});

process.env.NODE_ENV = 'test';
Expand Down Expand Up @@ -222,10 +229,17 @@ describe('plugin-minimize', () => {
"affectedHooks": "compilation",
"name": "SwcJsMinimizerRspackPlugin",
},
SwcCssMinimizerRspackPlugin {
"_options": undefined,
LightningCssMinimizerRspackPlugin {
"_options": {
"browserslist": [
"defaults",
],
"errorRecovery": false,
"removeUnusedLocalIdents": true,
"unusedSymbols": [],
},
"affectedHooks": undefined,
"name": "SwcCssMinimizerRspackPlugin",
"name": "LightningCssMinimizerRspackPlugin",
},
]
`,
Expand Down Expand Up @@ -267,10 +281,17 @@ describe('plugin-minimize', () => {
"affectedHooks": "compilation",
"name": "SwcJsMinimizerRspackPlugin",
},
SwcCssMinimizerRspackPlugin {
"_options": undefined,
LightningCssMinimizerRspackPlugin {
"_options": {
"browserslist": [
"defaults",
],
"errorRecovery": false,
"removeUnusedLocalIdents": true,
"unusedSymbols": [],
},
"affectedHooks": undefined,
"name": "SwcCssMinimizerRspackPlugin",
"name": "LightningCssMinimizerRspackPlugin",
},
]
`,
Expand Down Expand Up @@ -312,10 +333,17 @@ describe('plugin-minimize', () => {
"affectedHooks": "compilation",
"name": "SwcJsMinimizerRspackPlugin",
},
SwcCssMinimizerRspackPlugin {
"_options": undefined,
LightningCssMinimizerRspackPlugin {
"_options": {
"browserslist": [
"defaults",
],
"errorRecovery": false,
"removeUnusedLocalIdents": true,
"unusedSymbols": [],
},
"affectedHooks": undefined,
"name": "SwcCssMinimizerRspackPlugin",
"name": "LightningCssMinimizerRspackPlugin",
},
]
`,
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const CHAIN_ID = {
MINIMIZER: {
/** SwcJsMinimizerRspackPlugin */
JS: 'js',
/** SwcCssMinimizerRspackPlugin */
/** LightningCssMinimizerRspackPlugin */
CSS: 'css',
},
/** Predefined resolve plugins */
Expand Down
8 changes: 4 additions & 4 deletions website/docs/en/config/tools/bundler-chain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ For example, the `RULE.STYLUS` rule exists only when the Stylus plugin is regist

`MINIMIZER.[ID]` can match a certain minimizer.

| ID | Description |
| --------------- | ------------------------------------------- |
| `MINIMIZER.JS` | correspond to `SwcJsMinimizerRspackPlugin` |
| `MINIMIZER.CSS` | correspond to `SwcCssMinimizerRspackPlugin` |
| ID | Description |
| --------------- | ------------------------------------------------- |
| `MINIMIZER.JS` | correspond to `SwcJsMinimizerRspackPlugin` |
| `MINIMIZER.CSS` | correspond to `LightningCssMinimizerRspackPlugin` |
2 changes: 1 addition & 1 deletion website/docs/en/guide/basic/css-usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Please read the [React - CSS-in-JS](/guide/framework/react#css-in-js) section to

During the production build, Rsbuild compresses static assets such as CSS and JS to provide better transmission efficiency.

Rsbuild by default uses the built-in `SwcCssMinimizerRspackPlugin` plugin from Rspack to automatically compress CSS code during production builds.
Rsbuild by default uses the built-in `LightningCssMinimizerRspackPlugin` plugin from Rspack to automatically compress CSS code during production builds.

You can customize the CSS minimizer by using the [CSS Minimizer plugin](/plugins/list/plugin-css-minimizer) to switch to cssnano or other tools for CSS compression.

Expand Down
8 changes: 4 additions & 4 deletions website/docs/zh/config/tools/bundler-chain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Rsbuild 中预先定义了一些常用的 Chain ID,你可以通过这些 ID

通过 `MINIMIZER.[ID]` 可以匹配到对应的压缩工具。

| ID | 描述 |
| --------------- | ---------------------------------- |
| `MINIMIZER.JS` | 对应 `SwcJsMinimizerRspackPlugin` |
| `MINIMIZER.CSS` | 对应 `SwcCssMinimizerRspackPlugin` |
| ID | 描述 |
| --------------- | ---------------------------------------- |
| `MINIMIZER.JS` | 对应 `SwcJsMinimizerRspackPlugin` |
| `MINIMIZER.CSS` | 对应 `LightningCssMinimizerRspackPlugin` |
2 changes: 1 addition & 1 deletion website/docs/zh/guide/basic/css-usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Rsbuild 通过插件来支持社区流行的 CSS 预处理器,包括 Sass、Le

在生产环境构建时, Rsbuild 会将 CSS、JS 等静态资源进行压缩,以达到更好的传输效率。

Rsbuild 默认使用 Rspack 内置的 `SwcCssMinimizerRspackPlugin` 插件,在生产环境构建时自动压缩 CSS 代码。
Rsbuild 默认使用 Rspack 内置的 `LightningCssMinimizerRspackPlugin` 插件,在生产环境构建时自动压缩 CSS 代码。

你可以通过 [CSS Minimizer 插件](/plugins/list/plugin-css-minimizer) 来自定义 CSS 压缩工具,切换到 cssnano 或其他工具进行 CSS 压缩。

Expand Down

0 comments on commit 7a87d5c

Please sign in to comment.