Windows 上的 CoffeeScript?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3175561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:25:33  来源:igfitidea点击:

CoffeeScript on Windows?

windowscoffeescript

提问by Nick Perkins

How can I try CoffeeScript on Windows?

如何在 Windows 上试用 CoffeeScript?

The installation instructions are only for *nix: http://jashkenas.github.com/coffee-script/#installation

安装说明仅适用于 *nix:http: //jashkenas.github.com/coffee-script/#installation

EDIT:

编辑:

Since I asked this a while ago, many new answers have appeared. The number ( and quality ) of options for Windows users has been increased a lot. I "accepted" an answer a long time ago, then changed to other ( better ) answers as they came up, but I have now decided to not accept any answer, and let the community ( votes ) show which answers are best. Thanks to everyone for the input.

自从我前一段时间问这个问题以来,出现了许多新的答案。Windows 用户的选项数量(和质量)增加了很多。我很久以前“接受”了一个答案,然后在他们出现时更改为其他(更好的)答案,但我现在决定不接受任何答案,并让社区(投票)显示哪些答案是最好的。感谢大家的投入。

回答by liammclennan

UPDATE: See my other answer to this question, How can I compile CoffeeScript from .NET?for a far more accurate and up-to-date list of the current options.

更新:请参阅我对这个问题的其他回答,如何从 .NET 编译 CoffeeScript?有关当前选项的更准确和最新的列表。

CoffeeScript-Compiler-for-Windowsworks well.

CoffeeScript-Compiler-for-Windows运行良好。

回答by Colonel Panic

Maybe it was more complicated when this question was posted. But as of 2012, CoffeeScript is as easy to use on any platform. The instructionsare the same for Windows, Mac, or Linux

发布这个问题时可能会更复杂。但截至 2012 年,CoffeeScript 在任何平台上都同样易于使用。Windows、Mac 或 Linux的说明相同

  1. Install Nodejs from http://nodejs.org/
  2. Install CoffeeScript globally with the node package manager npm install -g coffeescriptor locally npm install --save-dev coffeescript
  3. Write a script in your favourite text editor. Save it, say as hello.coffee
  4. Run your script coffee hello.coffeeor compile it coffee -c hello.coffee(to hello.js)
  1. http://nodejs.org/安装 Nodejs
  2. 使用节点包管理器全局npm install -g coffeescript或本地安装 CoffeeScriptnpm install --save-dev coffeescript
  3. 在您最喜欢的文本编辑器中编写脚本。保存它,说为hello.coffee
  4. 运行您的脚本coffee hello.coffee或编译它coffee -c hello.coffee(到hello.js

回答by jashkenas

Node.js runs on Cygwin these days, so that's probably your best bet with getting CoffeeScript running on Windows. I'd try that first.

Node.js 现在在 Cygwin 上运行,所以这可能是让 CoffeeScript 在 Windows 上运行的最佳选择。我会先试试。

If you have a different preferred JavaScript runtime, you can probably use the prebuilt-compiler (extras/coffee-script.js). For example, if you include that script on a webpage, you can call

如果您有不同的首选 JavaScript 运行时,您可能可以使用预编译器 (extras/coffee-script.js)。例如,如果您在网页上包含该脚本,则可以调用

CoffeeScript.compile(code);

... to get back the compiled JavaScript string.

...取回编译后的 JavaScript 字符串。

UPDATE 2012-04-12: Cygwin is no longer needed to run Node on Windows. Microsoft worked with Joyent through 2H 2011 to improve node's support for Windows IOCP async IO. Node 0.6 was the first release of node to natively support Windows.

更新 2012-04-12:不再需要 Cygwin 在 Windows 上运行 Node。在 2011 年 2H 期间,Microsoft 与 Joyent 合作以改进节点对 Windows IOCP 异步 IO 的支持。Node 0.6 是第一个原生支持 Windows 的 node 版本

回答by Duncan Smart

You can run the CoffeeScript compiler under good old Window Script Host (cscript.exe), a standard component on Windows since Windows 98. Admittedly I tried this a while back and it didn't work, but I tried again recently and now all the standard CoffeeScript tests compile just fine.

您可以在旧的 Window Script Host (cscript.exe) 下运行 CoffeeScript 编译器,这是自 Windows 98 以来 Windows 上的标准组件。诚然,我曾尝试过一段时间,但没有奏效,但我最近再次尝试,现在所有的标准的 CoffeeScript 测试编译得很好。

A bit of plumbing code using a *.wsffile and coffee-script.jsis all you need. My code is on GitHub: https://github.com/duncansmart/coffeescript-windows

您只需要一些使用*.wsf文件和coffee-script.js的管道代码即可。我的代码在 GitHub 上:https: //github.com/duncansmart/coffeescript-windows

I blogged about it here: http://blog.dotsmart.net/2011/06/20/the-simplest-way-to-compile-coffeescript-on-windows/

我在这里写了博客:http: //blog.dotsmart.net/2011/06/20/the-simplest-way-to-compile-coffeescript-on-windows/

回答by PandaWood

You can use jcoffeescriptas a command-line solution.

您可以使用jcoffeescript作为命令行解决方案。

It uses a Java-based javascript engine (Rhino) and wraps up the task of compiling coffee-script.jsfrom the CoffeeScript project. This allows it to run the CoffeeScript compiler as a Java program.

它使用基于 Java 的 javascript 引擎 ( Rhino) 并完成了从CoffeeScript 项目编译coffee-script.js的任务。这允许它作为 Java 程序运行 CoffeeScript 编译器。

The command to use (on Windows/Linux) looks like this:

要使用的命令(在 Windows/Linux 上)如下所示:

java -jar jcoffeescript-1.0.jar < foo.coffee > foo.js

You will need to download & build the Java source code (use IntelliJ Community Editionto avoid downloading Ant) or a pre-built download for CoffeeScript v1.0.

您需要下载并构建 Java 源代码(使用IntelliJ 社区版以避免下载Ant)或预构建的 CoffeeScript v1.0 下载

I now use jcoffeescriptin place of the Ruby solution (another answer here), because this allows me to keep up with the latest CoffeeScriptversion.

我现在使用jcoffeescript代替 Ruby 解决方案(这里的另一个答案),因为这使我能够跟上最新的 CoffeeScript版本。

回答by PandaWood

You can use a command-line version of CoffeeScript by installing Ruby on Windowsand then installing the CoffeeScript Gem.

您可以通过在 Windows 上安装 Ruby然后安装CoffeeScript Gem来使用 CoffeeScript 的命令行版本。

After that, the command-line is available, for example, 'coffee bla.coffee' - to compile your CoffeeScript code down to JavaScript code.

之后,命令行可用,例如,'coffee bla.coffee' - 将您的 CoffeeScript 代码编译为 JavaScript 代码。

The only disadvantage doing it this way (not using Node.js) is that the Ruby version of CoffeeScript is restricted to version 0.3.2 - the last version written in Ruby before it was moved over to Node.js.

这样做的唯一缺点(不使用 Node.js)是 CoffeeScript 的 Ruby 版本仅限于 0.3.2 版——这是在移至 Node.js 之前用 Ruby 编写的最后一个版本。

*However, I still use the Ruby version of CoffeeScript in my current employment and my personal web page and I don't see much of a problem as this version of CoffeeScript is quite mature and most of the features listed on the CoffeeScriptwebsite can be used.

*但是,我在目前的工作和个人网页中仍然使用 Ruby 版本的 CoffeeScript,我认为没有太大问题,因为这个版本的 CoffeeScript 已经相当成熟,并且CoffeeScript网站上列出的大多数功能都可以用过的。

*striked out this last statement which was correct at the time but is becoming more incorrect every few days; CoffeeScript has now advanced a long way since 0.3.2 and is past 1.1

*删除这最后一句当时是正确的,但每隔几天就会变得更不正确;从 0.3.2 开始,CoffeeScript 已经取得了长足的进步,并且已经超过了 1.1

回答by Tom Lokhorst

There're already bunch of answers here, but let me add mine. I wrote a .NET library for compiling CoffeeScript on Windows.

这里已经有很多答案了,但让我添加我的。我编写了一个 .NET 库,用于在 Windows 上编译 CoffeeScript。

As jashkenas suggested, I've used the pre-compiled extras/coffee-script.jsfile.
Together with the Jurassic JavaScript compilerI've wrapped it all up in a single library: CoffeeSharp

正如 jashkenas建议的那样,我使用了预编译extras/coffee-script.js文件。
连同侏罗纪 JavaScript 编译器,我将它全部打包在一个库中:CoffeeSharp

The library also ships with a commandline tool and a HttpHandler for ASP.NET web development.

该库还附带了一个命令行工具和一个用于 ASP.NET Web 开发的 HttpHandler。

回答by Julian Birch

Since node.js is now ported to Windows, this is actually pretty easy:

由于 node.js 现在已移植到 Windows,这实际上非常简单:

http://www.colourcoding.net/blog/archive/2011/09/20/using-coffeescript-on-windows.aspx

http://www.colourcoding.net/blog/archive/2011/09/20/using-coffeescript-on-windows.aspx

回答by D_Guidi

I've used this one: https://bitbucket.org/maly/coffeescript-win/zealotslooks working well, althouth you need to manually need to update coffee.script from 0.95 to 1.0.1.

我使用过这个:https: //bitbucket.org/maly/coffeescript-win/zealots 看起来运行良好,虽然您需要手动将 coffee.script 从 0.95 更新到 1.0.1。

回答by liammclennan

If you want to use CoffeeScript in an ASP.NET application then you can use this HTTP handlerto serve compiled CoffeeScript code.

如果您想在 ASP.NET 应用程序中使用 CoffeeScript,那么您可以使用此 HTTP 处理程序来提供已编译的 CoffeeScript 代码。