Skip to content

MINIFY_CSS option #11839

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

Open
bdefore opened this issue Dec 24, 2021 · 1 comment
Open

MINIFY_CSS option #11839

bdefore opened this issue Dec 24, 2021 · 1 comment

Comments

@bdefore
Copy link

bdefore commented Dec 24, 2021

Is your proposal related to a problem?

  • Bundle size is larger than it needs to be because there is no option to minify/obfuscate CSS even though CRA already has tools to support it
  • Bots/scrapers can be a nuisance and can be partially mitigated by unique class names per build so that selector-based traversal is less reliable

Describe the solution you'd like

A MINIFY_CSS flag that enables style minification. A cousin to the GENERATE_SOURCEMAP option. Only operates for production builds.

If enabled, appropriate options could be passed to css-loader here (and postcss-loader):
https://github.com/facebook/create-react-app/blob/main/packages/react-scripts/config/webpack.config.js#L131

Or to css-minimizer-webpack-plugin here:
https://github.com/facebook/create-react-app/blob/main/packages/react-scripts/config/webpack.config.js#L300

The webpack.config.js has a shouldUseSourceMap that derives from GENERATE_SOURCEMAP.

An implementation suggestion from an earlier request is here: #8984 (comment)

An example of someone ejecting to achieve this: https://medium.com/swlh/minifying-tailwind-css-with-create-react-app-b8615a82b33b

This would not be a sensible default to leave enabled. This would break sites that rely on predictable selectors to function properly. Leaving the flag off on builds destined for integration testing would make them easier to author. A flag would seem most suitable.

Describe alternatives you've considered

Did not find a relevant flag in existing set: https://create-react-app.dev/docs/advanced-configuration

Aside from ejecting, running cssnano on resulting build output. Haven't tried since it would introduce fragility.

Additional context

Earlier requests for this feature marked stale here:
#8984
#6349

Larger scope: It may be worth considering a flag to remove unused styles via something like https://purgecss.com/

@zamarawka
Copy link

zamarawka commented Jan 18, 2022

In 2020 I already submitted PR for this feature #9223 , but i lost hope to get it merged 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants