question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unused compiled CSS classes aren't eliminated

See original GitHub issue

As titled. In the example below you can see that unused styles are bundled- I’d expect that rollup is able to remove them in context of CSS-Modules.

var styles = {"button":"Button__button","unused":"Button__unused"};

// eslint-disable-next-line no-unused-vars
function Button() {
  return /*#__PURE__*/React.createElement("div", {
    className: styles.button
  });
}

export default Button;

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
kzccommented, May 27, 2020

It’s not really a rollup thing. Property hoisting is handled by terser.

$ cat button.js
var styles = {"button": "Button__button", "unused": "Button__unused"};
function Button() {
    return /*#__PURE__*/React.createElement("div", {
        className: styles.button
    });
}
export default Button;
$ terser button.js --module -bc passes=3
export default function() {
    return React.createElement("div", {
        className: "Button__button"
    });
}

Or if you prefer the rollup CLI:

$ rollup button.js -p terser='{module:true,compress:{passes:3},output:{beautify:true}}' --silent
export default function() {
    return React.createElement("div", {
        className: "Button__button"
    });
}

I generally use terser --module -mc passes=3,unsafe,pure_getters depending on the code base, but YMMV.

1reaction
Anidetrixcommented, May 26, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

How Do You Remove Unused CSS From a Site?
To clean CSS with multiple pages just use that tool for all pages with different layouts. Then merge all exported CSS files to...
Read more >
Eliminating Unused CSS - SurviveJS
It walks through your code and figures out which CSS classes are being used as often ... At best, PurgeCSS can eliminate most,...
Read more >
Fix 'Remove Unused CSS' in lighthouse
The warning 'remove unused CS'S in Lighthouse appears when Lighthouse has found too many CSS rules on a page that are not being...
Read more >
[JIT] unused CSS not eliminated in watch mode #4098 - GitHub
In JIT watch mode, when the last instance of a class is removed from the source files, I would expect that the class...
Read more >
Purge-css is removing all css stylings instead of just the ...
Since your app is a ReactJS App, you want to purge css classes not used in the Javascript bundle compiled for the dev...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found