Compile CoffeeScript on Save?

fancy picture fancy · Jun 9, 2011 · Viewed 12.8k times · Source

Is there anyway to easily compile CoffeeScript on save? I'm using TextMate or Sublime Text 2.

Answer

Elf Sternberg picture Elf Sternberg · Jun 9, 2011

Coffeescript has a 'watch' feature. You could set up, as a semi-permanent process:

coffee –wc -o media/js/ src/coffee/*.coffee

And for every file with an extension ".coffee", the corresponding compiled ".js" file will be put into the target directory every time you save.

That said, I use a makefile and a fabfile, because my HTML is HAML, my CSS is LessCSS, and my development directory is not my test path, so I needed something smart enough to "build and deploy."

If your machine supports inotify, you could use inotifywait to watch your entire work path, and call Make as needed. But at that point, you're into hard-core geekery.