Solution 1:

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.

Solution 2:

You can also accomplish this without the command line:

  1. Add a build process to Sublime Text.
  2. Make sure that Save All on Build is selected in the Tools menu.
  3. Use ⌘B instead of ⌘S when saving.

So instead of compiling on save, you're saving on compile.

Solution 3:

The most straightforward solution with Sublime, is to install the Sublime package called Better Coffeescript (preferences --> package control --> install package...), and then make sure that its configuration includes "compileOnSave": true (preferences --> package settings --> Better Coffeescript...). Then restart Sublime.

For Sublime, anything else is not enough or too much extra components. Just came here after upgrading to Sublime 3, and it works like charm for Sublime 3 (as it did for Sublime 2, I just forgot about it at first).

Solution 4:

Well coffee --watch has 2 major flaws:

  • New files created after command has been issued aren't being watched
  • Requires manual initiation so there can be a chance you forget to do it, which doesn't sound more brilliant than forget to compile before you git commit it

The solution I came up with is a rather simple Bash script that takes coffee --watch a few steps further which will allow your working directory tree to be watched ever since system login, and automatically get compiled into JavaScript on each file save/change or new file creation:

http://blog.gantrithor.com/post/11609373640/carefree-coffeescript-auto-compiler

There may be more elegant way to do this, but this implementation works great =)