如何将多个源文件传递给 TypeScript 编译器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12699781/
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
How can I pass multiple source files to the TypeScript compiler?
提问by CCoder
TypeScript is designed for large-scale JavaScripty projects which typically consist of multiple internally produced files along with externally produced libraries. How does the TypeScript compiler (tsc) expect you to provide it with the complete set of files that make up a project?
TypeScript 是为大型 JavaScripty 项目设计的,这些项目通常由多个内部生成的文件和外部生成的库组成。TypeScript 编译器 (tsc) 如何期望您向它提供构成项目的完整文件集?
回答by deerchao
dir *.ts /b /s > ts-files.txt
tsc @ts-files.txt
del ts-files.txt
This will compile all *.ts
files in working directory and its sub directories. If you don't want to include sub directories, just remove the /s
part from the first line.
这将编译*.ts
工作目录及其子目录中的所有文件。如果您不想包含子目录,只需/s
从第一行中删除该部分即可。
Note that you can also add other arguments to the tsc
line. Here is what I'm using now for one of my projects:
请注意,您还可以向该tsc
行添加其他参数。这是我现在用于我的项目之一的内容:
tsc @ts-files.txt --out ..\output\deerchao.web.js --removeComments
回答by Peter Olson
tsc can compile multiple sources in sequence if you just give the names in order:
如果您只是按顺序给出名称,tsc 可以按顺序编译多个源:
tsc foo.ts bar.ts
You can also pass a text file containing a list of files and command line arguments from a text file using the @
command line argument.
您还可以使用命令行参数从文本文件传递包含文件列表和命令行参数的文本文件@
。
tsc @compile.txt
and the compile.txt
could look like this:
而compile.txt
看起来是这样的:
--module amd
foo.ts
bar.ts
Also note that if on file references another via an import
, tsc
will automatically figure that out without you having to explicitly list the file that it depends on.
另请注意,如果文件通过import
,引用另一个文件,tsc
则将自动计算出来,而无需明确列出它所依赖的文件。
回答by Centurion
In case anyone needs this for Mac OS X:
如果有人在 Mac OS X 上需要这个:
find . -name "*.ts" -type f >ts-files.txt
/usr/local/bin/tsc @ts-files.txt --module CommonJS --out ./Deploy/ServerMain.js --removeComments
rm ts-files.txt
回答by dSebastien
With TypeScript 1.5 (beta but the final version should be there soon), you can create a tsconfig.json file to configure the TypeScript compiler and the files to compile (among other things). See my answer over there: How to watch and compile all TypeScript sources?
使用 TypeScript 1.5(测试版,但最终版本应该很快就会出现),您可以创建一个 tsconfig.json 文件来配置 TypeScript 编译器和要编译的文件(以及其他内容)。请参阅那边的答案:如何观看和编译所有 TypeScript 源代码?
回答by Matthias
Or simply:
或者干脆:
find ./my/path/ -name \"*.ts\" -type f | tsc
回答by Stefan Rein
If someone needs multiple files pretranspiled before the actual project compiling, use a separate tsconfigwith the --projectcompiler option.
如果有人需要在实际项目编译之前预编译多个文件,请使用带有--project编译器选项的单独 tsconfig。
Compile a project given a valid configuration file. The argument can be a file path to a valid JSON configuration file, or a directory path to a directory containing a tsconfig.json file. See tsconfig.json documentation for more details.
编译一个给定有效配置文件的项目。该参数可以是有效 JSON 配置文件的文件路径,也可以是包含 tsconfig.json 文件的目录的目录路径。有关更多详细信息,请参阅 tsconfig.json 文档。
One use case would be the need of the resulting JS files used afterwards in command line arguments for ionic app scripts.
一个用例是需要随后在 ionic 应用程序脚本的命令行参数中使用的结果 JS 文件。