如何在开发网站时使用coffeescript?
您如何使用 CoffeeScript?它需要编译,所以 - 你用 CoffeScript 编写代码,编译它,然后在你的网站上插入真正的 JavaScript?
How do you use CoffeeScript? It need to be compiled, so - you write code in CoffeScript, compile it, and insert real JavaScript on your site?
不会花很多时间吗?还是有别的办法?
Doesn't it take a lot of time? Or is there some another way?
附:我已经看到了另一种方法 - 在开发阶段使用 coffeescript.js 库(大约 150k)在 text/coffeescript 脚本标签中插入咖啡脚本,并且只为生产版本编译并插入真正的 Javascript.
P.S. I've seen another way - to insert in development stage coffeescript in text/coffeescript script-tags with coffeescript.js library (about 150k), and compile only for production version and insert real Javascript.
推荐答案
答案是肯定的,你自己编译并包含生成的 JavaScript.
The answer is yes, you compile it and include the generated JavaScript on your side.
如果您使用的是 web 框架(rails、django 等),您应该查看以下咖啡脚本插件列表:https://github.com/jashkenas/coffee-script/wiki/Web-framework-plugins.当您将应用程序部署到服务器时,他们会将您的咖啡脚本编译为 javascript.
If you're using a web framework (rails, django etc) you should take a look at the following list of coffeescript plugins: https://github.com/jashkenas/coffee-script/wiki/Web-framework-plugins. They will compile your coffeescript to javascript when you deploy your app to a server.
使用带有 text/coffeescript
标签的 coffee-script 插件是另一种选择,gzip 压缩和压缩,它只有大约 39kB,但如果你将它包含在获得很多点击的页面上,它可以加起来我不认为你可以在不需要插件的情况下自己将咖啡脚本编译为 javascript 是一个好主意.
Using the coffee-script plugin with the text/coffeescript
tags is another option, gzipped and compressed, its only about 39kB, but that can add up if you include it on pages that get many hits and I don't think is a good idea when you can compile the coffeescript to javascript yourself without needing the plugin.
有 middleman 插件可以让您在开发过程中使用 CoffeeScript,然后编译和缩小用于部署.
There is the middleman plugin which will lets you work with CoffeeScript during development, then compile and minify it for deployment.
相关文章