-
Notifications
You must be signed in to change notification settings - Fork 29
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
Remove unused CSS #36
Comments
I agree, the unused CSS removal is a perfect feature for minifier. And there can be issues when any removal of CSS is done after the minification because, for example, mentioned email-remove-unused-css parses and renders back the code. The CSS renderer (stringifier) won't output minified code, what means minifying would need to be performed again, OR unused CSS removed first and only then whole thing minified. When minification does the CSS removal it's faster for user. email-remove-unused-css is for email code and was not designed to accept external stylesheets. That will be an issue for There is a PostHTML plugin to remove unused CSS, https://www.npmjs.com/package/postcss-remove-unused and looks like it accepts external stylesheets, although probably not |
How about using uncss? It seems that, at least theoretically, we could add uncss to the const uncss = require('uncss');
const render = require('posthtml-render');
[...]
function processStyleNode(tree, styleNode, cssnanoOptions) {
const css = Array.isArray(styleNode.content) ? styleNode.content.join(' ') : styleNode.content;
[...]
const html = render(tree, options);
uncss(html, { stylesheets: [], raw: css } (error, output) => { ... });
} Thoughts on this? |
Thanks, @fstanis for implementing that! I released this module and your other fixes as version 0.2.2. |
with email-remove-unused-css.
It's built with posthtml, but it currently cannot be used as a plugin and forces a reparse of the HTML. This should get fixed, though.
The text was updated successfully, but these errors were encountered: