安装依赖
yarn add postcss-comment postcss-import postcss-nested postcss-preset-env
配置postcss选项,在根目录创建postcss.config.js
// eslint-disable-next-line no-undef
module.exports = (ctx) => ({
parser: ctx.parser ? 'sugarss' : false,
map: ctx.env === 'development' ? ctx.map : false,
plugins: {
'postcss-preset-env': {
stage: 2,
browsers: 'last 2 versions',
},
'postcss-import': {},
'postcss-nested': {},
cssnano: ctx.env === 'production' ? {} : false,
},
});
使用postcss
<style lang="postcss">
p{
code{
color: red;
}
}
</style>