autocompile .coffee files and reload project

家住魔仙堡 提交于 2019-12-06 07:17:39

This should work:

coffee --watch --compile ./

Also, you can shorten the flags to -wc.

Nodemon will properly watch the coffeescript files if you explicitly specify their extension with -e js,coffee. This is counter to what the docs state and I've filed a ticket on this issue here: https://github.com/remy/nodemon/issues/312

Andrew Mao

What you're doing is pretty common in coffeescript libraries. Many libraries have a script to compile all coffeescript files in one directory to Javascript files in another. For example, the following Cakefile compiles from src/ to lib/. You can cake watch or cake build depending on what you want to do.

{print} = require 'util'
{spawn} = require 'child_process'

task 'build', 'Build lib/ from src/', ->
  coffee = spawn 'coffee', ['-c', '-o', 'lib', 'src']
  coffee.stderr.on 'data', (data) ->
    process.stderr.write data.toString()
  coffee.stdout.on 'data', (data) ->
    print data.toString()
  coffee.on 'exit', (code) ->
    callback?() if code is 0

task 'watch', 'Watch src/ for changes', ->
  coffee_src = spawn 'coffee', ['-w', '-c', '-o', 'lib', 'src']
  coffee_src.stderr.on 'data', (data) -> process.stderr.write data.toString()
  coffee_src.stdout.on 'data', (data) -> print data.toString()

However, if you're not running node but actually running a browser app, I would suggest using the fantastic hem. For that, I've also written a getting-started guide on here: https://stackoverflow.com/a/14993583/586086

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!