我可以在 Heroku 中运行咖啡脚本吗? [英] Can I run coffeescript in Heroku?
问题描述
我有一个用 CoffeeScript 编写的 node.js 应用程序.
I have a node.js app written in CoffeeScript.
我想知道在 Heroku 上托管应用需要什么.
I'm wondering what is needed in order to host the app on Heroku.
谢谢
推荐答案
由于 Heroku 的更新,它现在允许 npm
安装 coffee-script
来源.下面的答案是 Heroku 完全支持 node.js
之前的解决方法.对于当前更好的解决方案,请参阅评分较高的答案,解释如何在 Heroku 上简单地使用 npm
中的 coffee-script
.
Due to the updates with Heroku, it now allows for an npm
installation of the coffee-script
source. The answer below was a work-around before Heroku fully supported node.js
. For a better solution currently, please see the higher rated answer explaining how to simply use coffee-script
from npm
on Heroku.
说实话,最好的方法是像 Peter 建议的那样使用 coffee -c filename
事先编译它,但我想知道你是否可以有一种预加载"preload.js
将使用 coffeescript
作为 node_module
调用脚本,然后 compile() 要使用的脚本.这样您就可以在 heroku 上的节点中本地使用它们,而无需处理 repo 中的额外文件.
To be honest the best way would be to compile it before hand using coffee -c filename
like Peter suggested, but I wonder if you could have a sort of 'preload' preload.js
that will call the scripts using coffeescript
as a node_module
then compile() the script to be used. That way you can use them natively in node on heroku without dealing with extra files in your repo.
npm install coffee-script
然后在初始应用中,用javascript编写,并使用coffee的编译函数调用*.coffee
文件:
Then in the inital app, write it in javascript and call the *.coffee
files using coffee's compile function:
var coffee = require('coffee-script');
coffee.compile('./server.coffee');
// could be coffee.run(file) instead, not sure
并在 yourapp.coffee
中尝试
console.log 'It worked!'
我不确定这是否可行,或者这是否是该函数的正确语法.https://github.com/jashkenas/coffee-script/blob/master/lib/coffee-script.js#L24
I'm not sure if this would work, or if that's even the proper syntax for that function. https://github.com/jashkenas/coffee-script/blob/master/lib/coffee-script.js#L24
如果你想用 ruby 来做,这里是:
If you're asking about doing it in ruby, here's this:
演练如何在 Heroku 上的 rails 中使用 coffeescript:http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/
Walkthrough on how to use coffeescript in rails on Heroku: http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/
建议使用 bistro_car ( https://github.com/jnicklas/bistro_car )
It suggests using bistro_car ( https://github.com/jnicklas/bistro_car )
gem install bistro_car
mkdir -p app/scripts
并将其添加到您的 Rails conf/environment.rb
and adding it to your Rails conf/environment.rb
config.gem 'bistro_car'
如果我找到其他方法或其他方式来本地运行 *.coffee
javascript 应用程序,我会更新这个答案,但希望这会给你一些关于如何让它工作的想法.
If I find something else or another way to natively run *.coffee
javascript apps, I'll update this answer but hopefully this will give you some idea on how to get it to work.
这里还有几个例子,但它们似乎都在使用 ruby 和 node.js:
Here are a couple more examples, but they all seem to be using ruby vs node.js as well:
http://forrst.com/posts/Doing_CoffeeScript_on_Heroku_a_Ruby_gem-OBkhttp://www.tangiblecolors.com/first-steps-with-coffeescript-and-how-to-use
http://forrst.com/posts/Doing_CoffeeScript_on_Heroku_a_Ruby_gem-OBk http://www.tangiblecolors.com/first-steps-with-coffeescript-and-how-to-use
希望这会有所帮助.
这篇关于我可以在 Heroku 中运行咖啡脚本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!