Compile CoffeeScript on Save?

前端 未结 7 1098
花落未央
花落未央 2020-12-24 01:11

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

相关标签:
7条回答
  • 2020-12-24 01:28

    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)

    0 讨论(0)
  • 2020-12-24 01:33
    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

    0 讨论(0)
  • 2020-12-24 01:34

    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).

    0 讨论(0)
  • 2020-12-24 01:43

    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.

    0 讨论(0)
  • 2020-12-24 01:47

    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.

    0 讨论(0)
  • 2020-12-24 01:50

    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 =)

    0 讨论(0)
提交回复
热议问题