Is there anyway to easily compile CoffeeScript on save? I'm using TextMate or Sublime Text 2.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- Keeping track of variable instances
Well
coffee --watch
has 2 major flaws:git commit
itThe 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 =)
I like codekit :) Simple and effective way to compile coffeescript, sass, less, haml, and more, with lots of niceties. http://incident57.com/codekit/
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).
The best solution I have found compared with all other static compilation tools like StaticMatic, Middleman, etc.
Very flexible and configurable and does not rely on any preset folder structure. Just add
controller.rb
and write some Ruby. Lots of helpers for doing clever things before/after compilation.https://github.com/winton/stasis
You can also accomplish this without the command line:
Save All on Build
is selected in theTools
menu.So instead of compiling on save, you're saving on compile.
Coffeescript has a 'watch' feature. You could set up, as a semi-permanent process:
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.