mirror of
https://github.com/zhigang1992/customize-cra.git
synced 2026-01-12 22:46:33 +08:00
feat: add post-css plugins (#42)
This commit is contained in:
20
index.js
20
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
|
||||
};
|
||||
|
||||
18
readme.md
18
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 })
|
||||
]),
|
||||
);
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user