Does TypeScript provide an explicit Public API for NodeJS Module Access?

前端 未结 5 610
失恋的感觉
失恋的感觉 2020-12-31 11:22

From within a node app I would like to do:

var typeScript = require(\'typescript\'); 

typeScript.compile(\'...\')

I\'m looking to implemen

5条回答
  •  礼貌的吻别
    2020-12-31 11:57

    Currently it is not possible to achieve a compilation just by having a require and calling compile. If you can look at the harness.ts there is a compiler module that provides a rather simple way of doing it but I would suggest you to call tsc externally.

    ///
    import exec = module('child_process');
    
    var child = exec.exec('tsc foo.ts',
      function (error, stdout, stderr) {
        if (error !== null) {
          console.log('exec error: ' + error);
        }
    });
    

    I believe this would do the job.

提交回复
热议问题