-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react项目:在configoveride.js中addPostcssPlugins添加postcss-pxtorem无效 #340
Comments
有么有大佬 帮解决下 |
参考MR:0f88a26 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.postcssOptions && u.options.postcssOptions.ident === "postcss") {
if (!u.options.postcssOptions.plugins) {
u.options.postcssOptions.plugins = () => [...plugins];
}
if (u.options.postcssOptions.plugins) {
const originalPlugins = u.options.postcssOptions.plugins;
u.options.postcssOptions.plugins = () => [...originalPlugins(), ...plugins];
}
}
}));
return config;
};
``` ` |
你好?我用您这个方法似乎,还是不起作用
|
|
// 重写 addPostcssPlugins 方法
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.postcssOptions && u.options.postcssOptions.ident === 'postcss') {
if (!u.options.postcssOptions.plugins) {
u.options.postcssOptions.plugins = plugins;
}
if (u.options.postcssOptions.plugins) {
const originalPlugins = u.options.postcssOptions.plugins;
u.options.postcssOptions.plugins = [...originalPlugins, ...plugins];
}
}
}));
return config;
};
用法:
addPostcssPlugins([['postcss-pxtorem', {
rootValue: 100,
propList: ['*'],
}]]) |
这是我完整的配置:
运行后报错:originalPlugins is not iterable 似乎打印了两次 第一次是 数组形式,第二次是个 函数形式 |
不过我做了修改 改成了 下面这个就生效了
|
addPostcssPlugins([
require("postcss-pxtorem")({
rootValue: 16,
propList: [""],
replace:true
// propList: ['', '!border*', '!font-size*', '!letter-spacing'],
// propWhiteList: []
}),
]),
The text was updated successfully, but these errors were encountered: