Search code examples
infinite-loopwatchpostcss

postcss-cli: Combine --watch and --replace for same file without infinite loop


When I try to use the replace and watch attributes for the same file(s), I get an infinite loop, meaning that the watch notices the change that e.g. autoprefixer just made to the file and thus starts the command again and again. Here is the command that I put into an NPM script or use on the command line:

postcss css/*.css -u autoprefixer --replace --watch

(or as shortform: postcss css/*.css -u autoprefixer -r -w)

It basically all works (autoprefixes are applied, the file is replaced and watched), the only problem is the infinite loop. So, is it possible to use --watch and --replace for the same file or directory?


Solution

  • Use the --poll option too:

    postcss css/*.css -u autoprefixer --replace --watch --poll
    

    The docs are sparse about it, but it works in v3.2.0 of postcss-cli.