Socket
Socket
Sign inDemoInstall

postcss-loader

Package Overview
Dependencies
10
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    postcss-loader

PostCSS loader for webpack


Version published
Maintainers
1
Install size
1.14 MB
Created

Package description

What is postcss-loader?

The postcss-loader npm package is a loader for webpack that allows you to use PostCSS to process CSS with JavaScript. It enables the use of PostCSS plugins to perform various operations on CSS files, such as autoprefixing, minification, and custom transformations.

What are postcss-loader's main functionalities?

Autoprefixing

Automatically adds vendor prefixes to CSS rules using values from Can I Use. It is useful for supporting multiple browser versions.

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              postcssOptions: {
                plugins: [
                  require('autoprefixer')
                ]
              }
            }
          }
        ]
      }
    ]
  }
};

CSS Minification

Optimizes and minifies CSS files to reduce file size and improve load times.

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              postcssOptions: {
                plugins: [
                  require('cssnano')()
                ]
              }
            }
          }
        ]
      }
    ]
  }
};

Custom Transformations

Applies custom transformations or future CSS features using PostCSS plugins.

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              postcssOptions: {
                plugins: [
                  require('postcss-custom-properties')()
                ]
              }
            }
          }
        ]
      }
    ]
  }
};

Other packages similar to postcss-loader

Changelog

Source

0.4.1

  • Use only Promise API to catch PostCSS errors.

0.4

  • Add PostCSS asynchronous API support.
  • Fix source map support (by Richard Willis).
  • Add warnings API support.
  • Better output for CSS syntax errors.

0.3

  • Use PostCSS 4.0.

0.2

  • Use PostCSS 3.0.

0.1

  • Initial release.

Readme

Source

PostCSS for Webpack Build Status

PostCSS loader for webpack to postprocesses your CSS with PostCSS plugins.

Sponsored by Evil Martians

Usage

Set postcss section in webpack config:

var autoprefixer = require('autoprefixer-core');
var csswring     = require('csswring');

module.exports = {
    module: {
        loaders: [
            {
                test:   /\.css$/,
                loader: "style-loader!css-loader!postcss-loader"
            }
        ]
    },
    postcss: [autoprefixer, csswring]
}

Now your CSS files requirements will be processed by selected PostCSS plugins:

var css = require('./file.css');
// => CSS after Autoprefixer and CSSWring

Plugins Packs

If you want to process different styles by different PostCSS plugins you can define plugin packs in postcss section and use them by ?pack=name parameter.

module.exports = {
    module: {
        loaders: [
            {
                test:   /\.docs\.css$/,
                loader: "style-loader!css-loader!postcss-loader?pack=cleaner"
            },
            {
                test:   /\.css$/,
                loader: "style-loader!css-loader!postcss-loader"
            }
        ]
    },
    postcss: {
        defaults: [autoprefixer, csswring],
        cleaner:  [autoprefixer({ browsers: [] })]
    }
}

Safe Mode

If you add ?safe=1 to requirement, PostCSS will try to correct any syntax error that it finds in the CSS. For example, it will parse a { as a {}.

var css = require('postcss?safe=1!./broken')

Keywords

FAQs

Last updated on 26 Apr 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc