Compile CoffeeScript on Save?
Is there anyway to开发者_如何学Python easily compile CoffeeScript on save? I'm using TextMate or Sublime Text 2.
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.
You can also accomplish this without the command line:
- Add a build process to Sublime Text.
- Make sure that
Save All on Build
is selected in theTools
menu. - Use ⌘B instead of ⌘S when saving.
So instead of compiling on save, you're saving on compile.
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).
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 =)
If you also want bundling, buildr offers watching and bundling too: https://github.com/balupton/buildr.npm
The (Java|Coffee)Script and (CSS|Less) (Builder|Bundler|Packer|Minifier|Merger|Checker)
gem install stasis
stasis -d
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
I like codekit :) Simple and effective way to compile coffeescript, sass, less, haml, and more, with lots of niceties. http://incident57.com/codekit/
精彩评论