Transforming TypeScript into JavaScript

前端 未结 11 1294
再見小時候
再見小時候 2020-12-08 02:01

I\'m wondering how is it possible to transform the TypeScript into JavaScript in a cross platform manner. I\'m aware about availability of node package manager for typescrip

11条回答
  •  一个人的身影
    2020-12-08 02:38

    I have a project which compiles Typescript to Javascript in Java:

    https://github.com/martypitt/typescript4j

    As discussed in other answers, this makes use of Rhino, so has no dependencies on npm or node.

    Here's an example:

    // Instantiate the compiler:
    TypescriptCompiler compiler = new TypescriptCompiler();
    
    // Compile a string:
    String output = compiler.compile("class Greeter { greeting: string; }");
    
    // Or, compile and output to a file:
    compiler.compile(new File("example.ts"), new File('output.js'));
    

    I use it in another project - 'Bakehouse' to perform on-the-fly compilation of typescript resources within Spring environments

提交回复
热议问题