typescript 通过 tsc 命令打字稿:输出到单个文件,无需连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17243897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:49:43  来源:igfitidea点击:

TypeScript via tsc command: Output to single file without concatenation

typescripttsc

提问by Vojtěch

Is there a way of compiling single .ts file to different directory?

有没有办法将单个 .ts 文件编译到不同的目录?

The only way from the manual command of compilation to different directory is via --outcommand, but it also does concatenation of dependent files, which I don't want:

从手动编译命令到不同目录的唯一方法是通过--out命令,但它也会连接依赖文件,这是我不想要的:

--out FILE|DIRECTORY        Concatenate and emit output to single file | Redirect output structure to the directory

Is there a way of redirecting the output WITHOUT concatenation of input files?

有没有办法在不连接输入文件的情况下重定向输出?

采纳答案by Alex Filatov

Unfortunately it's impossible to compile multiple *.tsfiles into one *.jswithout concatenation. Because it's impossible on API level of typescript compile options.

不幸的是,将多个*.ts文件编译成一个*.js而不串联是不可能的。因为在打字稿编译选项的 API 级别上是不可能的。

See --outoption:

查看--out选项:

DEPRECATED. Use --outFile instead.

已弃用。改用 --outFile 。

Documentation of --outFileoption:

--outFile选项文件:

Concatenate and emit output to single file. The order of concatenation is determined by the list of files passed to the compiler on the command line along with triple-slash references and imports. See output file order documentation for more details.

连接并将输出发送到单个文件。串联顺序由在命令行上传递给编译器的文件列表以及三斜杠引用和导入决定。有关更多详细信息,请参阅输出文件顺序文档。

All typescript compiler options

所有打字稿编译器选项

回答by Jeffery Grajkowski

It does one or the other. If there's no .jsextension on that file name it should assume a directory.

它有一个或另一个。如果.js该文件名没有扩展名,它应该假设一个目录。

tsc -out output.js filea.ts fileb.ts...<- output to single file output.js

tsc -out output.js filea.ts fileb.ts...<- 输出到单个文件 output.js

tsc -out output filea.ts fileb.ts...<- output individual files to dir output

tsc -out output filea.ts fileb.ts...<- 将单个文件输出到目录输出

tsc -out output/output.js filea.ts fileb.ts...<- output to single file in another directory

tsc -out output/output.js filea.ts fileb.ts...<- 输出到另一个目录中的单个文件