Book Image

LESS WEB DEVELOPMENT COOKBOOK

Book Image

LESS WEB DEVELOPMENT COOKBOOK

Overview of this book

Table of Contents (19 chapters)
Less Web Development Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Removing unused CSS using Grunt


When your project grows or when you are using CSS frameworks, such as Bootstrap, your compiled CSS code can contain many selectors that are never used. This unused CSS code will have a negative effect on the performance of your website. The unused CSS plugin can remove this unused selector from your CSS code.

Getting ready

The only requirement for this recipe is to have the unused CSS plugin installed and loaded in your Gruntfile.js file. If you have not installed this plugin in the Installing Grunt plugins recipe of this chapter, you can do so using the following command in the root of your project:

$ npm install grunt-uncss –save-dev

How to do it…

You can add the following configuration for the watch task to your Gruntfile.js file:

    uncss: {
      dist: {
      files: {
        'css/style.css' : ['index.html']
      }
     }
    }

The preceding code only checks the index.html file for unused selectors. You can add a list of HTML to check using and array as...