Git Product home page Git Product logo

csso-loader's Introduction

csso-loader

NPM version Build Status Dependency Status NPM downloads Code Climate Test Coverage

CSSO loader module for webpack.

Usage

Documentation: Using loaders

Installation

npm install csso-loader --save-dev

Examples

Using csso-loader with css-loader.

module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'css-loader!csso-loader',
      }
    ]
  }
};

Advanced options

restructure

Default: true

csso performs structural optimization for better compression by default. Use -restructure in case you want to disable it.

module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'css-loader!csso-loader?-restructure',
      }
    ]
  }
};

Also it can be disabled by restructure boolean option in csso object of webpack config.

module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'css-loader!csso-loader',
      }
    ]
  },
  csso: {
    restructure: false
  }
};

debug

Default: false

debug is using to get details about the minification process.

module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'css-loader!csso-loader?debug',
      }
    ]
  }
};

Also you can set debug option in csso object of webpack config. It can be boolean or a positive number from 1 to 3 (greater number for more details).

module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'css-loader!csso-loader',
      }
    ]
  },
  csso: {
    debug: 3
  }
};

comments

Default: exclamation or true

csso leave all exclamation comments by default (i.e. /*! .. */). Use '-comments' to remove all comments.

module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'css-loader!csso-loader?-comments',
      }
    ]
  }
};

Also you can set comments option in csso object of webpack config. It can be boolean or string (use first-exclamation to remove all comments except first one with exclamation).

module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'css-loader!csso-loader',
      }
    ]
  },
  csso: {
    comments: 'first-exclamation'
  }
};

usage

With usage option you can set data about CSS usage. For example, white lists (tags, ids and classes) can be set to filter unused selectors and related CSS rules as well. See Usage data in csso documentation for more details.

module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'css-loader!csso-loader',
      }
    ]
  },
  csso: {
    usage: {
      tags: ['span', 'div'],
      ids: ['id1'],
      classes: ['class1', 'class2', 'class3', 'class4']
      scopes: [
        ['class1', 'class2'],
        ['class3', 'class4']
      ]
    }
  }
};

logger

To log how CSS is transforming through compression stages use logger option. First argument is a stage name, and second one is AST of current state CSS or null.

module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'css-loader!csso-loader',
      }
    ]
  },
  csso: {
    logger: function(stage, ast) {
      console.log(stage, ast);
    }
  }
};

License

MIT © Andrew Smirnov

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.