How can I compile CoffeeScript from .NET?

后端 未结 18 1804
后悔当初
后悔当初 2020-12-23 01:54

I want to write an HttpHandler that compiles CoffeeScript code on-the-fly and sends the resulting JavaScript code. I have tried MS [JScript][1] and IronJS without success. I

相关标签:
18条回答
  • 2020-12-23 02:25

    I don't have a direct answer, (I hope you find one), but maybe take a look at the following to see how it might be done.

    • Jint - JavaScript interpreter for .NET
    • Using IKVM to compile Rhino would get rid of the Java runtime requirement.
    • jcoffeescript. I haven't looked at jcoffeescript, but I think it depends on JRuby and Rhino. You could possibly IKVM.NET this as well.
    0 讨论(0)
  • 2020-12-23 02:25

    IronJS now supports CoffeeScript and is generally faster than the other .NET JS engines:

    I have a blog post about wiring the two together here:
    http://otac0n.com/blog/2011/06/29/CoffeeDemo-A-Simple-Demo-Of-IronJS-Using-CoffeeScript.aspx

    0 讨论(0)
  • 2020-12-23 02:26

    Instead of shelling out to CScript you could shell out to Node.js (here are self-contained Windows binaries)

    0 讨论(0)
  • 2020-12-23 02:30

    I wrote an inteructive shell using v8.

    https://github.com/mattn/coffee-script-v8

    This work as single executable file. (Don't use external files) It can't use require(). But enough to learn coffeescript.

    0 讨论(0)
  • 2020-12-23 02:31

    I've managed to compile CoffeeScript from .NET using IKVM, jcoffeescript and Rhino. It was straightforward, except that the JCoffeeScriptCompiler constructor overload without parameters didn't work. It ran OK with a java.util.Collections.EMPTY_LIST as parameter.

    This is how I did it:

    1. Download IKVM, jcoffeescript and Rhino.
    2. Run ikvmc against js.jar, creating js.dll.
    3. Run ikvmc against the jcoffeescript jar.
    4. Add a reference to the jcoffeescript dll in Visual Studio. More references may be needed, but you will be warned about those.
    5. Run new org.jcoffeescript.JCoffeeScriptCompiler(java.util.Collections.EMPTY_LIST).compile() in your code.

    The next step would be to create a build task and/or an HTTP handler.

    0 讨论(0)
  • 2020-12-23 02:32

    You specifically said that you wanted to write a runtime compiler, so this may not be exactly what you are looking for, but if the main point is to have a way to generate the javascript result, the Mindscape Web Workbench is interesting. It is a free extension for Visual Studio.NET 2010 and available in the Extension Manager. It gives Intellisense, syntax highlighting and compiles to JS as you write. I am just getting started using it but looks promising. Scott Hanselman talks about it here. It also supports LESS and Sass.

    0 讨论(0)
提交回复
热议问题