Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 不带CLI的可传输类型脚本_Node.js_Typescript - Fatal编程技术网

Node.js 不带CLI的可传输类型脚本

Node.js 不带CLI的可传输类型脚本,node.js,typescript,Node.js,Typescript,如何在不使用命令行的情况下传输Typescript 我想要一个脚本build.js来构建我的应用程序 到目前为止,我发现typescript包有一个transfile(inputArgument,compileOptions)方法,但我在他们的文档中找不到任何关于这一点的信息 我可以使用tsc-pserver构建我的项目,因此我设想以下方法可以奏效: const tsc = require('typescript'); tsc.transpile("", { project: "ser

如何在不使用命令行的情况下传输Typescript

我想要一个脚本
build.js
来构建我的应用程序

到目前为止,我发现
typescript
包有一个
transfile(inputArgument,compileOptions)
方法,但我在他们的文档中找不到任何关于这一点的信息

我可以使用
tsc-pserver
构建我的项目,因此我设想以下方法可以奏效:

const tsc = require('typescript');

tsc.transpile("", {
    project: "server",
});
然后我会使用
节点build.js

我无法使
tsc.transfile()
正常工作(我不知道
inputArgument
是什么),并且在他们的文档中也找不到如何做到这一点:在没有CLI的情况下从代码进行传输。

您可以使用该模块

就你而言:

const { spawn } = require('child_process');

const ls = spawn('tsc', ['-p', 'server']);

ls.stdout.on('data', (data) => {
  console.log(`stdout: ${data}`);
});

ls.stderr.on('data', (data) => {
  console.log(`stderr: ${data}`);
});

ls.on('close', (code) => {
  console.log(`child process exited with code ${code}`);
});

这不是我想要的,但它确实解决了问题。非常感谢。