Skip to content
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

Unused compiled CSS classes aren't eliminated #280

Open
StarpTech opened this issue May 25, 2020 · 6 comments
Open

Unused compiled CSS classes aren't eliminated #280

StarpTech opened this issue May 25, 2020 · 6 comments

Comments

@StarpTech
Copy link

StarpTech commented May 25, 2020

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;
@SASUKE40
Copy link
Collaborator

It is worthy, let me do some research about implementation.

@StarpTech
Copy link
Author

StarpTech commented May 26, 2020

@Anidetrix
Copy link

@StarpTech I believe this is related to rollup/rollup#2201 (comment)

@StarpTech
Copy link
Author

@Anidetrix thanks!

@kzc
Copy link

kzc commented 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.

@CSDev0
Copy link

CSDev0 commented Mar 2, 2022

some update about this? sound a very nice addon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants