Use TypeScript compiler from node

后端 未结 6 1794
既然无缘
既然无缘 2021-02-02 17:30

It\'s pretty easy to do this with coffee-script.

var coffee = require(\'coffee-script\');
coffee.compile(\"a = 1\");
//=> \'(function() {\\n  var a;\\n\\n  a          


        
6条回答
  •  天命终不由人
    2021-02-02 17:35

    Official documentation about how to use TypeScript transpiler API to generate JavaScript source from a .ts file:

    https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#user-content-transpiling-a-single-file

    Official documentation about how to use TypeScript compiler API to compile a .ts file or a TS project to

    https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#user-content-a-minimal-compiler

    (the later doesn't answer the original question but is very common to access /modify the AST and then transpile to object language so it could be usefull)

提交回复
热议问题