【构建工具】PostCSS快速配置

1. 安装依赖包
npm i -D postscss postcss-cli
npm i -D autoperfixer postcss-preset-env 
npm i -D stylelint stylelint-config-standard
npm i -D postcss-pxtorem

// 执行命令 npx postcss style.css -o dist.css
  1. postcss // PostCSS核心包
  2. postcss-cli // PostCSS命令行
  3. autoprefixer // autoprefixer插件
  4. postcss-preset-env // preset-env插件,转换嵌套css语法
  5. stylelint // 检查css语法的插件
  6. stylelint-config-standard // stylelint一些基本的规则
  7. postcss-pxtorem // 将px单位转换成rem
2. PostCSS配置
// postcss.config.js
const autoprefixer = require('autoprefixer');
const postcssPresetEnv = require('postcss-preset-env');
const stylelint = require('stylelint');
const postcssPxtorem = require('postcss-pxtorem')

module.exports = {
  plugins: [
    stylelint,
    autoprefixer,
    postcssPresetEnv({
      stage: 0,
    }),
    postcssPxtorem,
  ]
}

.stylelintrc.json
{
  "extends": "stylelint-config-standard"
}


// .browserslistrc
cover 99.5%
3. 总结 

        浏览器兼容性是前端开发常遇到的问题,现代前端构建工具已经可以帮我们处理很多兼容问题,比如:Babel语法转换和polyfill可以解决JavaScript层面的大部分兼容问题,而PostCSS的autoprefixer以及语法转换可以解决CSS层面的大部分兼容问题。

相关推荐

  1. 构建工具PostCSS快速配置

    2024-03-16 05:26:03       43 阅读
  2. vite配置postcss

    2024-03-16 05:26:03       35 阅读
  3. postcss

    2024-03-16 05:26:03       37 阅读
  4. vue 配置 postcss-px2rem

    2024-03-16 05:26:03       36 阅读
  5. PotCSS

    2024-03-16 05:26:03       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-16 05:26:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-16 05:26:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-16 05:26:03       82 阅读
  4. Python语言-面向对象

    2024-03-16 05:26:03       91 阅读

热门阅读

  1. HTML-DAY1

    2024-03-16 05:26:03       31 阅读
  2. C++(1): std::vector的使用

    2024-03-16 05:26:03       41 阅读
  3. 【 React 】对React refs的理解?应用场景?

    2024-03-16 05:26:03       44 阅读
  4. hcie数通和云计算选哪个好?

    2024-03-16 05:26:03       42 阅读
  5. FPGA的应用方向

    2024-03-16 05:26:03       29 阅读
  6. 低代码大屏设计器使用入门级图文教程

    2024-03-16 05:26:03       41 阅读
  7. linux 的.bashrc .bash_profile .profile分别作用

    2024-03-16 05:26:03       41 阅读