【问题标题】:Use Autoprefixer in npm without Gulp在不使用 Gulp 的情况下在 npm 中使用 Autoprefixer
【发布时间】:2015-04-29 02:59:48
【问题描述】:

我是否需要安装所有这些依赖项和 devDependencies 才能在节点中使用 autoprefixer,尽管我根本不使用 gulp?

https://github.com/postcss/autoprefixer/blob/master/package.json

我想在这样的节点中使用它:

     "scripts": {
       "build:css": "autoprefixer -b 'last 2 versions' <assets/styles/main.css | cssmin > dist/main.css"
     }

如此处所述:http://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/

但我收到一条错误消息,提示系统找不到文件,不知道是哪个文件。

我用它安装的

npm install autoprefixer --save-dev

【问题讨论】:

  • autoprefixer 的 devDependencies 仅在您使用 autoprefixer 本身时才需要(这就是它们是 devDependencies 的原因)。见docs.npmjs.com/files/package.json#devdependencies“我收到一条错误消息,提示系统找不到文件” 嗯,这太糟糕了。不要认为我们可以对此做任何事情(只有这么少的信息)。
  • 你描述的应该可以。您没有为其他人提供足够的信息来帮助诊断它为什么不起作用。
  • 好的,谢谢!似乎错误在构建脚本中。我只是找不到有关要使用的参数的任何信息。 npm run autoprefixer -h 没有帮助:/ 我也不明白如何使用github.com/ai/browserslist 获取浏览器列表?
  • 也对此感兴趣。您可能会从scripts 条目在github.com/postcss/autoprefixer#cli 处运行postcss 命令。我没有尝试过,因为我使用 WebStorm,它有一个 LESS 文件观察器,并且我已经安装了less-autoprefix-plugin。另请参阅 [using npm run` 使用 less 构建和观看,以及 browserify](https://gist.github.com/substack/7819530) and [fs-change](https://www.npmjs.com/package/fs-change). As for the browserlist, you just pass a string like "last 2 versions"` 到 autoprefixer。

标签: node.js npm autoprefixer


【解决方案1】:

Autoprefixer 不能自行运行。它需要像这样作为 postcss-cli 的一部分运行:

postcss --use autoprefixer *.css -d build/

(来自https://github.com/postcss/autoprefixer#cli

保存-dev postcss-cli,然后重新格式化您的 build:css 以匹配

postcss --use autoprefixer -b 'last 2 versions' &lt;assets/styles/main.css | cssmin &gt; dist/main.css

如果您仍有问题,请告诉我们。

【讨论】:

  • postcss --use autoprefixer input.css -d build/ Plugin Error: Cannot find module 'input.css' ?
【解决方案2】:

安装:npm install -g postcss-cli autoprefixer

用法(订单很重要!):postcss main.css -u autoprefixer -d dist/

【讨论】:

    【解决方案3】:

    在 autoprefixer 10 和 postcss-cli v8 发布之前,只需将 autoprefixer 降级到 ^9.8.6。

    【讨论】:

      猜你喜欢
      • 2016-04-13
      • 1970-01-01
      • 2020-01-28
      • 2023-03-06
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-31
      相关资源
      最近更新 更多