Skip to content

Commit c854b19

Browse files
committedMay 17, 2024·
feat(bundler-webpack): replace postcss-csso with lightningcss (close #1349)
1 parent 10378e1 commit c854b19

File tree

6 files changed

+764
-27
lines changed

6 files changed

+764
-27
lines changed
 

‎.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"frontmatter",
2929
"globby",
3030
"gtag",
31+
"lightningcss",
3132
"mdit",
3233
"nprogress",
3334
"prefetch",

‎e2e/docs/styles/css-container.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Check if the `@container` rule could be supported and minimized correctly.
2+
3+
<div class="container">
4+
5+
Container text
6+
7+
</div>
8+
9+
<style>
10+
.container {
11+
container-type: inline-size;
12+
}
13+
.container p {
14+
font-size: clamp(.75rem, calc(100cqw / 40), 2rem);
15+
text-align: left;
16+
}
17+
@container (max-width: 480px) {
18+
.container p {
19+
text-align: center;
20+
font-weight: bold;
21+
}
22+
}
23+
</style>

‎packages/bundler-webpack/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@
4646
"chokidar": "^3.6.0",
4747
"copy-webpack-plugin": "^12.0.2",
4848
"css-loader": "^7.1.1",
49+
"css-minimizer-webpack-plugin": "^7.0.0",
4950
"esbuild-loader": "~4.1.0",
5051
"express": "^4.19.2",
5152
"html-webpack-plugin": "^5.6.0",
53+
"lightningcss": "^1.24.1",
5254
"mini-css-extract-plugin": "^2.9.0",
5355
"postcss": "^8.4.38",
54-
"postcss-csso": "^6.0.1",
5556
"postcss-loader": "^8.1.1",
5657
"style-loader": "^4.0.0",
5758
"vue": "^3.4.27",

‎packages/bundler-webpack/src/build/createClientConfig.ts

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createRequire } from 'node:module'
22
import type { App } from '@vuepress/core'
33
import { fs } from '@vuepress/utils'
44
import CopyWebpackPlugin from 'copy-webpack-plugin'
5+
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
56
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
67
import type Config from 'webpack-chain'
78
import { createClientBaseConfig } from '../config/index.js'
@@ -83,6 +84,16 @@ export const createClientConfig = async (
8384
// enable runtimeChunk
8485
config.optimization.runtimeChunk(true)
8586

87+
// minify css
88+
config.optimization
89+
.minimizer('css-minimizer-webpack-plugin')
90+
.use(CssMinimizerPlugin, [
91+
{
92+
minify:
93+
CssMinimizerPlugin.lightningCssMinify as CssMinimizerPlugin.BasicMinimizerImplementation<unknown>,
94+
},
95+
])
96+
8697
// disable performance hints
8798
if (!app.env.isDebug) {
8899
config.performance.hints(false)

‎packages/bundler-webpack/src/config/handleModuleStyles.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { createRequire } from 'node:module'
22
import autoprefixer from 'autoprefixer'
33
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
4-
import postcssCsso from 'postcss-csso'
54
import type Config from 'webpack-chain'
65
import type {
76
LessLoaderOptions,
@@ -69,7 +68,7 @@ export const handleModuleStyles = ({
6968
.loader(require.resolve('postcss-loader'))
7069
.options({
7170
postcssOptions: {
72-
plugins: [autoprefixer, postcssCsso],
71+
plugins: [autoprefixer],
7372
},
7473
...options.postcss,
7574
})

‎pnpm-lock.yaml

+726-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.