是否可以将 .coffee 脚本文件加载到浏览器并执行? [英] Is is possible to load .coffee script file to browser and execute?
问题描述
我正在尝试在 sample.coffee 文件中加载咖啡脚本以及 coffee-script.js 文件,并对 HTML 执行一些简单的操作.但我无法加载 sample.coffee 文件.
I am trying to load coffee script inside a sample.coffee file along with the coffee-script.js file and perform some simple operations on the HTML. But i am not able to load the sample.coffee file.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="sample.coffee" type="text/coffeescript"></script>
<script src="coffee-script.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
这是 sample.coffee 中的咖啡脚本代码
Here is the coffeescript code inside sample.coffee
message = "Welcome to Coffeescript"
alert message
我参考了博客 http://forgivingworm.wordpress.com/2010/09/27/running-coffeescript-in-browser/
我试图在 .cshtml 上的 MVC4 项目中运行它.所以我在MS世界下运行.
I trying to run this in MVC4 project on .cshtml. So I am running under MS world.
我不确定这是否可能?任何对此的见解将不胜感激.
I am not sure if this is possible or not? any insight into this would be greatly appreciated.
推荐答案
我可以使用 CoffeeSharp http://tomlokhorst.github.com/CoffeeSharp/ 它为 .coffee 文件提供处理程序,还将咖啡脚本转换为浏览器上的 javascript.
I am able to solve this issue by using the CoffeeSharp http://tomlokhorst.github.com/CoffeeSharp/ It gives handler for .coffee files also converts the coffeescript to javascript on the browser.
我还能够在构建事件本身期间将咖啡脚本编译为 javascript,从而解决部署和性能相关问题.
Also I am able to compile the coffeescript to javascript during the build event itself which solves deployment and performance related issues.
这篇关于是否可以将 .coffee 脚本文件加载到浏览器并执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!