I am trying to remove unused css classes from my application using clean-css for WebPack.
To build this project, I use React , scss , WebPack and PostCss to build and compile everything.
So far I have managed to make progress, but something is wrong, and I do not know why, but the expected result is incorrect. I have a very simple setup for testing these scenarios, so these are my index.html and app.js files (the only files I have):
index.html
<body> <nav> <a href="">home</a> </nav> <hr /> <div id="app"></div> <footer class="my-other-heading"></footer> </body>
app.js
class App extends React.Component { render() { return ( <h1 className="my-other-heading">Mamamia!</h1> ); } } render(<App />, window.document.getElementById("app"));
In css files I use Normalize.css (with a bunch of css classes) and only 3 user classes:
.my-class { background-color: #CCDDEE; } .my-heading { color: red; } .my-other-heading { color: blue; }
The expected output should contain only these classes:
html, body, nav, a, hr, div, footer, h1, .my-other-heading
However, it has some other classes:
.my-heading, h2, h3, h4, [type='checkbox'] (and other similar, eg: [type='button']
Why is this happening? It removes almost all the classes that it should, but some of them are still here, and classes that are not explicitly used in the index file. I donβt know if they are saved due to some other declaration on the side of React, but I only refer to src files. This is my css config config:
new PurifyCSSPlugin({ paths: glob.sync([ path.join(__dirname, '..', 'src', '**/*.html'), path.join(__dirname, '..', 'src', '**/*.js'), ]), })