Remove unused css and duplicated css rules from your website. This tool removes duplicated rules and searches in html and js for unused css. Please keep in mind that not all unused css can be found, because of js injections! In my test 80-90% of unused css can be removed. This supports all kind off css frameworks, bootstrap, tailwindcss, foundation and more....
Check out the webpack plugin for usage with webpack.
To utilize for node.js install the the npm module:
$ npm install rm-unused-css --saveCheck out the example folder!
constrmUnusedCss=require('rm-unused-css');constcssSource='css/style.css';rmUnusedCss(cssSource,{path: './**/+(*.html|*.htm|*.js)',override: true}).then((result)=>{console.log(result.file,result.newContent)});Source: [cssSource]
Could be a single file path, array or a string with CSS content.
{// Glob path to the js and html files. Set to null or false if you don't want to remove unused selectorspath: '**/+(*.html|*.htm|*.js)',// Override the input fileoverride: false,// exclude filesexclude: [],// RegExp css class patterns. Example: /myclass_.*/whitelistPatterns: [],blacklistPatterns: [],// glob package optionsglobOptions: {ignore: 'node_modules/**/*'}}- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request