简介:
不同的浏览器对样式表的兼容性不一样,需要手动添加浏览器前缀,较为麻烦,使用webpack加载器配置postCSS自动添加css兼容前缀较为方便
安装:
npm i postcss-loader autoprefixer -D
- 在项目根目录中创建postcss的配置文件postcss.config.js,并初始化配置:
const autoprefixer = require('autoprefixer')
module.exports = {
plugins: [autoprefixer]//挂在插件
}
- 在webpack.config.js中module->rules数组中添加css的加载规则
{test: /\.css$/, use: ['style-loader', 'css-loader', 'postcss-loader']},