13

Do I need to install all these dependencies and devDependencies to use autoprefixer in node, although I do not use gulp at all?

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

I want to use it in node like this:

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

as described here: http://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/

But I get an error saying that the system cannot find a file, don´t know which file it means.

I installed it with

npm install autoprefixer --save-dev
Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
Bolko
  • 155
  • 1
  • 1
  • 9
  • 1
    The devDependencies of autoprefixer are only needed if you are working on autoprefixer itself (that's why they are devDependencies). See https://docs.npmjs.com/files/package.json#devdependencies . *"i get an error saying that the system cannot find a file"* Well, that's too bad. Don't think we can do anything about it (with that little information). – Felix Kling Feb 26 '15 at 16:22
  • What you describe should work. You have not provided enough information for others to help diagnose why it isn't working. – Sukima Feb 26 '15 at 16:53
  • Ok thanks! It seems the error is in the build script. I just can´t find any information on the parameters to use. npm run autoprefixer -h doesn´t help :/ I also dont understand how to get a browserlist with https://github.com/ai/browserslist? – Bolko Feb 26 '15 at 17:17
  • Also interested in this. You'd presumably run the `postcss` command at https://github.com/postcss/autoprefixer#cli from a `scripts` entry. I haven't tried that because I use WebStorm, which has a LESS file watcher, and I've installed the [less-autoprefix-plugin](https://github.com/less/less-plugin-autoprefix). See also [`using `npm run` to build and watch with less and 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"` to autoprefixer. – Dan Dascalescu Jul 09 '15 at 01:51

3 Answers3

5

Autoprefixer doesn't run on it's own. It needs to be run as part of postcss-cli like so:

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

(from https://github.com/postcss/autoprefixer#cli)

Save-dev postcss-cli and then reformat your build:css to match

postcss --use autoprefixer -b 'last 2 versions' <assets/styles/main.css | cssmin > dist/main.css

Then let us know if you're still having problems.

Jeff Heaton
  • 51
  • 1
  • 2
  • 1
    postcss --use autoprefixer input.css -d build/ Plugin Error: Cannot find module 'input.css' ? – daGo Jul 05 '18 at 10:27
4

Installation: npm install -g postcss-cli autoprefixer

Usage (order matters!): postcss main.css -u autoprefixer -d dist/

daGo
  • 2,584
  • 26
  • 24
0

In the case of autoprefixer 10 and before postcss-cli v8 released, just downgrade autoprefixer to ^9.8.6.

Abdulrahman Hashem
  • 1,481
  • 1
  • 15
  • 20