Skip to content

[@lit-labs/rollup-plugin-minify-html-literals] feat: enable minimizing modern css features like nesting, container queries - #5208

Merged
justinfagnani merged 6 commits into
lit:mainfrom
bencbradshaw:fix-css-minify-use-lightningcss
Apr 26, 2026
Merged

justinfagnani merged 6 commits into
lit:mainfrom
bencbradshaw:fix-css-minify-use-lightningcss

Conversation

@bencbradshaw

Copy link
Copy Markdown
Collaborator

These changes modernize the plugin's CSS minification, improve output quality and compatibility, and provide robust support for modern CSS features.

Fixes #5205
Alternative To PR 5205

Changes

Replaced clean-css with LightningCSS for CSS minification

  • clean-css is unmaintained and lacks support for modern CSS
  • LightningCSS is actively maintained with full support for current CSS standards

Fixes longstanding issues:

  1. Modern CSS features now work correctly
  • Container queries, native CSS nesting, and other modern features are fully supported
  • LightningCSS options can be passed through for customization
  1. Template expressions in CSS literals and <style> tags now work as expected
  • Preserves characters after expressions
  • Maintains semicolons between rules
const myVar = 12;
css`
h1 {
  font-size: ${myVar}px;
  color: #000;
}
`
// Now correctly minifies to:
css`h1{font-size:${myVar}px;color:#000}`

Why LightningCSS?

After evaluating several approaches:

  • Option A: Fork and maintain clean-css
  • Option B: Use dart-sass for minification
  • Option C: Adopt a well-maintained library with modern CSS support

Option C emerged as the clear choice. LightningCSS provides everything needed out of the box. While dart-sass was considered, it strips nesting rules during compilation, effectively removing support for this modern feature. LightningCSS, by contrast, preserves native CSS nesting through the minification process.

  • something to be aware of is how lightningcss is opinionated on its "optimizations" while it minifies. For example, color: white is transformed to color: #fff. These transforms can be controlled by passing the lightningcss options and with their visitor api

- Updated README to reflect the use of html-minifier-next and lightningcss.
- Removed clean-css dependency and related code.
- Introduced new options for lightningcss in the minification strategy.
- Enhanced minification strategy to support modern CSS features like nesting and container queries.
- Updated tests to verify CSS minification behavior with lightningcss.
@changeset-bot

changeset-bot Bot commented Jan 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6635241

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lit-labs/rollup-plugin-minify-html-literals Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Lookwe69

Lookwe69 commented Jan 9, 2026

Copy link
Copy Markdown

Warning point, LightningCSS is not perfect with modern CSS

E.g.
parcel-bundler/lightningcss#1036
parcel-bundler/lightningcss#1084

@bencbradshaw
bencbradshaw requested a review from augustjk January 10, 2026 17:32
@bencbradshaw

Copy link
Copy Markdown
Collaborator Author

Warning point, LightningCSS is not perfect with modern CSS

E.g. parcel-bundler/lightningcss#1036 parcel-bundler/lightningcss#1084

good callout and warning. Definitely something to be aware of. I may look into adding some contributions over into their repo and see if I can advance :state support and other new css features.

…up-plugin-minify-html-literals.spec.ts

Co-authored-by: Chad Adams <[email protected]>
@bencbradshaw
bencbradshaw dismissed cadamsdev’s stale review February 5, 2026 04:21

accepted suggestion

@7nik

7nik commented Apr 24, 2026

Copy link
Copy Markdown

It should close #5207 instead.

Hope the blocking issues will be resolved soon so I can enable the plugin back.

@justinfagnani justinfagnani left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @bencbradshaw ! Sorry for the delay in reviewing.

@justinfagnani
justinfagnani merged commit fb64afc into lit:main Apr 26, 2026
8 checks passed
kyubisation pushed a commit to kyubisation/lit that referenced this pull request May 7, 2026
…s features like nesting, container queries (lit#5208)

Replace clean-css with lightningcss for CSS minification

- Updated README to reflect the use of html-minifier-next and lightningcss.
- Removed clean-css dependency and related code.
- Introduced new options for lightningcss in the minification strategy.
- Enhanced minification strategy to support modern CSS features like nesting and container queries.
- Updated tests to verify CSS minification behavior with lightningcss.
@lit-robot lit-robot mentioned this pull request May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants