diff --git a/index.js b/index.js index 88c154c..3256587 100644 --- a/index.js +++ b/index.js @@ -250,6 +250,23 @@ const disableChunk = () => config => { return config; }; +const addPostcssPlugins = (plugins) => config => { + const rules = config.module.rules.find(rule => Array.isArray(rule.oneOf)) + .oneOf; + rules.forEach(r => r.use && r.use.forEach(u => { + if (u.options && u.options.ident === "postcss") { + if (!u.options.plugins) { + u.options.plugins = () => [...plugins]; + } + if (u.options.plugins) { + const originalPlugins = u.options.plugins; + u.options.plugins = () => [...originalPlugins(), ...plugins]; + } + } + })); + return config; +} + module.exports = { override, addBundleVisualizer, @@ -269,5 +286,6 @@ module.exports = { babelInclude, addBabelPreset, addBabelPresets, - disableChunk + disableChunk, + addPostcssPlugins }; diff --git a/readme.md b/readme.md index efea0e5..304fb33 100644 --- a/readme.md +++ b/readme.md @@ -317,3 +317,21 @@ To use it, just apply it and run the dev server with `yarn start --watch-all`. ```js watchAll(); ``` + +### add post-css plugins + +To add post-css plugins, you can use `addPostcssPlugins`. + +```js +const { + override, + addPostcssPlugins +} = require("customize-cra"); + +module.exports = override( + addPostcssPlugins([ + require('postcss-px2rem')({ remUnit: 37.5 }) + ]), +); + +``` \ No newline at end of file