Skip to content

Commit

Permalink
feat(bundler-webpack): replace postcss-csso with lightningcss (close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed May 17, 2024
1 parent 10378e1 commit c854b19
Show file tree
Hide file tree
Showing 6 changed files with 764 additions and 27 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"frontmatter",
"globby",
"gtag",
"lightningcss",
"mdit",
"nprogress",
"prefetch",
Expand Down
23 changes: 23 additions & 0 deletions e2e/docs/styles/css-container.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Check if the `@container` rule could be supported and minimized correctly.

<div class="container">

Container text

</div>

<style>
.container {
container-type: inline-size;
}
.container p {
font-size: clamp(.75rem, calc(100cqw / 40), 2rem);
text-align: left;
}
@container (max-width: 480px) {
.container p {
text-align: center;
font-weight: bold;
}
}
</style>
3 changes: 2 additions & 1 deletion packages/bundler-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@
"chokidar": "^3.6.0",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^7.1.1",
"css-minimizer-webpack-plugin": "^7.0.0",
"esbuild-loader": "~4.1.0",
"express": "^4.19.2",
"html-webpack-plugin": "^5.6.0",
"lightningcss": "^1.24.1",
"mini-css-extract-plugin": "^2.9.0",
"postcss": "^8.4.38",
"postcss-csso": "^6.0.1",
"postcss-loader": "^8.1.1",
"style-loader": "^4.0.0",
"vue": "^3.4.27",
Expand Down
11 changes: 11 additions & 0 deletions packages/bundler-webpack/src/build/createClientConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createRequire } from 'node:module'
import type { App } from '@vuepress/core'
import { fs } from '@vuepress/utils'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import type Config from 'webpack-chain'
import { createClientBaseConfig } from '../config/index.js'
Expand Down Expand Up @@ -83,6 +84,16 @@ export const createClientConfig = async (
// enable runtimeChunk
config.optimization.runtimeChunk(true)

// minify css
config.optimization
.minimizer('css-minimizer-webpack-plugin')
.use(CssMinimizerPlugin, [
{
minify:
CssMinimizerPlugin.lightningCssMinify as CssMinimizerPlugin.BasicMinimizerImplementation<unknown>,
},
])

// disable performance hints
if (!app.env.isDebug) {
config.performance.hints(false)
Expand Down
3 changes: 1 addition & 2 deletions packages/bundler-webpack/src/config/handleModuleStyles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createRequire } from 'node:module'
import autoprefixer from 'autoprefixer'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import postcssCsso from 'postcss-csso'
import type Config from 'webpack-chain'
import type {
LessLoaderOptions,
Expand Down Expand Up @@ -69,7 +68,7 @@ export const handleModuleStyles = ({
.loader(require.resolve('postcss-loader'))
.options({
postcssOptions: {
plugins: [autoprefixer, postcssCsso],
plugins: [autoprefixer],
},
...options.postcss,
})
Expand Down
Loading

0 comments on commit c854b19

Please sign in to comment.