Use TypeScript compiler from node

后端 未结 6 1684
既然无缘
既然无缘 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:48

    better-require could help you achieve this.

    It lets you require() typescript files - no pre-compilation needed - and a bunch of other file formats (coffeescript, clojurescript, yaml, xml, etc.)

    require('better-require')();
    var myModule = require('./mymodule.ts');
    

    Disclosure: I wrote better-require.

提交回复
热议问题