PostCSS 是一个允许使用 JS 插件转换样式的【工具】
autoprefixer 添加了 vendor 浏览器前缀的【插件】
PostCSS 文档:https://github.com/postcss/postcss/blob/main/docs/README-cn.md
PostCSS Github: https://github.com/postcss/postcss
安装
npm i postcss autoprefixer
Node.js使用代码实例
// 引入工具和插件
const Postcss = require("postcss");
const Autoprefixer = require("autoprefixer");
// 设置插件
const processor = Postcss([Autoprefixer]);
// 处理css
const css = `
.box{
transform: scale(0.5);
}
`;
processor.process(css, { from: undefined }).then(result => {
result.warnings().forEach(warn => {
console.warn(warn.toString());
});
console.log(result.css);
});
/*
输出:
.box{
-webkit-transform: scale(0.5);
transform: scale(0.5);
}
*/