PostCSS plugin separate the flex child element style into a selector.
将 flex 子元素样式分为选择器。
.foo {
color: red;
flex: 1;
}
.foo {
color: red;
}
.flex_foo {
flex: 1;
}
postcss@^7.0.0
postcss-loader@^3.0.0
{
prefix: 'flex_'; // 子元素样式前缀
validSelector: function (rule.selector) { // 有效的选择器
return true; // 返回 false 则不处理
}
}
Step 1: Install plugin:
npm install --save-dev postcss postcss-flex-item
Step 2: Check you project for existed PostCSS config: postcss.config.js
in the project root, "postcss"
section in package.json
or postcss
in bundle config.
If you do not use PostCSS, add it according to official docs and set this plugin in settings.
Step 3: Add the plugin to plugins list:
module.exports = {
plugins: [
+ require('postcss-flex-item', { prefix: 'flex_' }),
require('autoprefixer')
]
}