Simply watches a Less file and compiles it on save.
Sometimes installing something like Gulp or Grunt is annoying if all you want to do is have a simple watch+compile going on. This includes PostCSS for the sake of Autoprefixer but you can obviously also add other PostCSS plugins to this script with ease.
Install Less, PostCSS & AutoPrefixer as a baseline.
npm i less postcss autoprefixer
You can also install other PostCSS plugins you'd like to use. There's lots. Look, I even keep a list 👀.
I wrote this/tested this on node v4.2.1
so make sure you have at least that version of node installed. It may work on some earlier versions as well, but it's ES6exual so it will probably break on any pre-4.0.0
version. Check your version by running node -v
.
Pro Tip: Use nvm
to quickly jump between node versions.
Run node watch.js your-input-less-file.less your-output-css-file.css
to start waching your file. If no arguments are supplied, it will attempt to watch styles.less
. If only one argument is supplied, it will output to styles.css
.