【问题标题】:PostCSS Autoprefixer not working with command linePostCSS Autoprefixer 不适用于命令行
【发布时间】:2019-04-19 22:16:13
【问题描述】:

现在,我正在一个项目中工作,我必须支持 ie10 的 flexbox,我正在尝试通过终端独立地自动为我的一些 CSS 代码添加前缀。

该项目不支持任何构建工具,如 gulp 或 webpack。

所以我安装了 postcss 和 autoprefixer 如下:

npm install -g postcss autoprefixer

然后我尝试像这样为单个文件添加前缀:

npx postcss --use autoprefixer --autoprefixer.flexbox --autoprefix.browser "> 0%" -o main.css test.css

它适用于我的大部分代码,但它不包含 ie10 中 flexbox 的任何前缀。

我做错了吗?

【问题讨论】:

  • 您的目标是最新的浏览器,因为您在--autoprefix.browser 打错字了,应该是autoprefixer.browser

标签: css postcss autoprefixer


【解决方案1】:

您调用的 cli 命令是针对 postcss-cli-simple 而不是 postcss 本身或 postcss-cli

要使用你的命令,你必须安装这个包

npm install postcss-cli-simple autoprefixer

然后就可以使用这个命令了

./node_modules/.bin/postcss --use autoprefixer --autoprefixer.browsers "ie 10" -o main.css test.pcss

这个命令会转换这个:

body {
  display: flex;
  flex: 1 0 calc(1vw - 1px);
}

进入这个

body {
  display: -ms-flexbox;
  display: flex;
  -ms-flex: 1 0 calc(1vw - 1px);
      flex: 1 0 calc(1vw - 1px);
}

【讨论】:

    【解决方案2】:

    尝试使用.browserslistrc文件

    last 20 versions
    

    Link

    【讨论】:

      猜你喜欢
      • 2018-05-19
      • 1970-01-01
      • 2016-03-29
      • 2017-09-07
      • 2011-03-28
      • 2019-06-23
      • 1970-01-01
      • 2020-06-20
      • 1970-01-01
      相关资源
      最近更新 更多