# Apply postcss plugins to webpack css asset
This webpack plugin gets css, extracted by [ExtractTextPlugin](https://github.com/webpack/extract-text-webpack-plugin) and apply postcss plugins to it.

### Why?
If you use postcss-loader, not all its plugins are effective in file-by-file processing. For instance, css structural optimizations or media query packaging better apply to one css production file, that can be generated by ExtractTextPlugin.

# Installation
`npm i postcss-assets-webpack-plugin`

# Options
* `test` - regular expression for matching files that returned from ExtractTextPlugin.
* `plugins` - array of postcss plugins
* `log` - boolean if plugin can print info to the console, `true` by default

# Usage
Simple example of webpack config that tranforms css-modules with less and postcss. Autoprefixer is used in development _and_ production, mqpacker and csswring are used only for production build.

```
import webpack from 'webpack';
import csswring from 'csswring';
import mqpacker from 'mqpacker';
import autoprefixer from 'autoprefixer';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import PostCSSAssetsPlugin from 'postcss-assets-webpack-plugin';
 
const lessLoader = 'css?modules&importLoaders=1&localIdentName=[hash:10]!postcss!less';
 
webpackConfig = {
  <...>
  plugins: [
    new ExtractTextPlugin('[name].css'),
 		
    new PostCSSAssetsPlugin({
      test: /\.css$/,
      log: true,
      plugins: [
        // Pack same CSS media query rules into one media query rule
        mqpacker,
        // Minify CSS file with source maps. That’s only
        csswring({preservehacks: true, removeallcomments: true}),
      ],
    }),
  ],
  
  postcss() {
    return [autoprefixer({browser: 'last 2 version', cascade: false})]
  },
  
  module: {
    loaders: [
      test: /\.less$/,
      loader: process.env.NODE_ENV === 'development' ? 'style' + lessLoader : ExtractTextPlugin.extract(lessLoader),
    ],
  },
};
```
