简体   繁体   English

将JavaScript转换为Coffee?

[英]Converting JavaScript to Coffee?

In a Rails project with only a Coffee file, can I add a JavaScript file? 在仅包含Coffee文件的Rails项目中,可以添加JavaScript文件吗?

If not, am I supposed to convert each JavaScript file to Coffee? 如果没有,我应该将每个JavaScript文件都转换为Coffee吗?

You may use both JavaScript and Coffee files side-by-side in a Rails 3/4 app. 您可以在Rails 3/4应用程序中同时使用JavaScriptCoffee文件。

Coffee files are just a convenience. 咖啡档案只是一种方便。 They are all compiled to browser-compatible JavaScript files when the application is run. 运行应用程序时,它们都将编译为与浏览器兼容的JavaScript文件。

So, using a JavaScript file is acceptable. 因此,使用JavaScript文件是可以接受的。 The Asset pipeline will know how to handle both appropriately. 资产管道将知道如何适当地处理这两者。

This depends on the 'coffee-rails' gem being present in your Gemfile. 这取决于您的Gemfile中是否存在“ coffee-rails” gem。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM