-
Notifications
You must be signed in to change notification settings - Fork 33
Please Consider cssnano
Instead of clean-css
#174
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
Comments
I am thinking about lightningcss recently. Haven't evaluated that yet |
Rust speed is awesome. Unfortunately that'll also likely mean I won't be able to use it, as my project does run in browsers as well as the server and edge workers.. |
It ships a wasm library to run in browsers as well https://lightningcss.dev/docs.html#from-deno-or-in-browser. |
There are some CSS properties that clean-css will not support, such as A quick recipe if you want to use lightningcss right now: import htmlminifier from 'html-minifier-terser';
import lightningcss from 'lightningcss';
const encoder = new TextEncoder;
const decoder = new TextDecoder;
const minified = await htmlminifier.minify('...', {
/**
* @param {String} text
* @param {'inline' | 'media' | undefined} type
* @returns {String}
*/
minifyCSS: (text, type) => {
// function wrapCSS(text, type)
// https://github.com/terser/html-minifier-terser/blob/c4a7ae0bd08b1a438d9ca12a229b4cbe93fc016a/src/htmlminifier.js#L355
switch (type) {
case 'inline':
text = `*{${text}}`;
break;
case 'media':
text = `@media ${text}{a{top:0}}`;
break;
}
const minified = decoder.decode(lightningcss.transform({ code: encoder.encode(text), minify: true }).code);
// function unwrapCSS(text, type)
// https://github.com/terser/html-minifier-terser/blob/c4a7ae0bd08b1a438d9ca12a229b4cbe93fc016a/src/htmlminifier.js#L366
/** @type {RegExpMatchArray | null} */
let m;
switch (type) {
case 'inline':
m = minified.match(/^\*\{([\s\S]*)\}$/);
return m ? m[1] : minified;
case 'media':
m = minified.match(/^@media ([\s\S]*?)\s*{[\s\S]*}$/);
return m ? m[1] : minified;
default:
return minified;
}
},
}); |
👋 I'm working on a project that leverages html-minifier-terser and have long been a fan of the project. Unfortunately, it's using
clean-css
which has been unmaintained for some time now and the owner hasn't had time to give it bugfix updates in a while.cssnano
has been enjoying a lot of active development, and is built atop postcss which has a pretty proven track record. Postcss uses a tokenizer just as clean-css does, but somewhat more efficient, which should mean a speed boost. https://github.com/cssnano/cssnanoWould the project consider swapping
clean-css
forcssnano
?The text was updated successfully, but these errors were encountered: