Remove unused CSS classes from frameworks like bootstrap in a react project
As djfdev already wrote purgecss works quite well: purgcss simply searches all JavaScript files for occurrences of the CSS class strings of the used CSS files and removes those which cannot be found.
Purge-css is removing all css stylings instead of just the unused ones
Since your app is a ReactJS App, you want to purge css classes not used in the Javascript bundle compiled for the dev or production environment.
You can update your postcss.config.js
file to match on .js files.
module.exports = {
plugins: [
purgecss({
content: ["./src/**/*.js"],
// Treat every word in the bundle as a CSS selector
defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || []
}),
]
};
Remove unused css / js code on Release Build in Visual Studio
Use Webpack's Tree Shaking
Module bundler's like Webpack do it on the fly with the cost of minor configuration effort.
Related Topics
How to Use Tick/Checkmark Symbol (✓) Instead of Bullets in Unordered List
Prevent Linebreak After </Div>
How to Use Div Class and Id Together in CSS
How to Fix The Height of a <Div> Element
Angular2 Sub Component Break CSS Relationship
Make an Image to Fit Its Parent Dimensions
How to Customize Only with CSS for HTML5 Input Range Slider-Vertical
How to Make a Div with a Rails Link Clickable
Custom Fonts with Different Vertical Metrics Between Os's
Ie9 Suddenly CSS Case Sensitive
How to Create a Mobile Friendly Website [Infrastructure]
Center Text in HTML Number Input