Skip to content

Commit f427f01

Browse files
committed
Allow to use extra postcss plugins after css-modules related plugins
1 parent b6acfec commit f427f01

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,34 @@ Usage:
254254
require('file.css').className
255255
```
256256

257+
### Use extra postcss plugins
258+
259+
You can add your own [postcss](http://postcss.org/) plugins into this loader pipeline.
260+
It could be better for performance than using extra `postcss-loader`, because plugin will be called in the chain with other
261+
plugins used by `css-loader`, without extra parsing of css.
262+
263+
Usage:
264+
```js
265+
// webpack.config.js
266+
var autoprefixer = require("autoprefixer")
267+
module.exports = {
268+
modules: [
269+
{
270+
test: /\.css$/,
271+
loader: [
272+
"style",
273+
"css?modules&afterModules=autoprefixer"
274+
]
275+
}
276+
]
277+
cssLoader: {
278+
autoprefixer: function(pipeline) {
279+
pipeline.use(autoprefixer)
280+
}
281+
}
282+
}
283+
```
284+
257285
## License
258286

259287
MIT (http://www.opensource.org/licenses/mit-license.php)

lib/processCss.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
176176
parserPlugin(parserOptions)
177177
]);
178178

179+
if (
180+
query.afterModules &&
181+
options.loaderContext.options.cssLoader &&
182+
typeof options.loaderContext.options.cssLoader[query.afterModules] === "function"
183+
) {
184+
options.loaderContext.options.cssLoader[query.afterModules](pipeline)
185+
}
186+
179187
if(minimize) {
180188
var minimizeOptions = assign({}, query);
181189
["zindex", "normalizeUrl", "discardUnused", "mergeIdents", "reduceIdents"].forEach(function(name) {

0 commit comments

Comments
 (0)