Use TypeScript compiler from node

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

    Since TypeScript's NPM module doesn't export any public interface, the only way to do this currently is to execute the tsc process.

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

    An issue has been opened to request a public interface for the TypeScript module.

提交回复
热议问题