How do I identify and eliminate unused CSS styles from my bloated stylesheet?

后端 未结 7 1506
天涯浪人
天涯浪人 2020-12-10 10:39

I have a legacy stylesheet that is now full of unused styles. The problem is identifying the necessary from the unnecessary. Are there any tools to help with this?

相关标签:
7条回答
  • 2020-12-10 11:06

    Remove Unused CSS automatically using Grunt

    Gruntfile.js

    module.exports = function (grunt) {
    
        grunt.initConfig({
            uncss: {
                dist: {
                    files: [
                        { src: 'index.html', dest: 'css/test.css' }
                    ]
                }
            },
          cssmin: {
                dist: {
                    files: [
                        { src: 'css/test.css', dest: 'cleancss/testmin.css' }
                    ]
                }
            }
        });
    
        // Load the plugins
        grunt.loadNpmTasks('grunt-uncss');
        grunt.loadNpmTasks('grunt-contrib-cssmin');
    
        // Default tasks.
        grunt.registerTask('default', ['uncss', 'cssmin']);
    
    };
    
    0 讨论(0)
提交回复
热议问题