Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript via tsc command: Output to single file without concatenation

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

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

--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?

like image 736
Vojtěch Avatar asked Jun 21 '13 20:06

Vojtěch


People also ask

How do I compile multiple TypeScript files into one file?

Explanation: tsc: It stands for TypeScript compiler which is used to invoke the compiler in order to compile the TypeScript files. –out: It is a CLI (Command Line Interface) command which concatenates the TypeScript files and emits the output to a single JS file. outputFile.

Is it possible to combine multiple .ts files into a single .js file?

Can we combine multiple . ts files into a single . js file? Yes, we can combine multiple files.

How do you combine ts files and output as common js?

Click on the TypeScript Build tab. Select Combine JavaScript output into file: and type in a name to use for your combined file in the input field right next to the option. Remember you can use variables in this field. For example: "$(ProjectDir)dist\js\myCombinedFile.


2 Answers

Unfortunately it's impossible to compile multiple *.ts files into one *.js without concatenation. Because it's impossible on API level of typescript compile options.

See --out option:

DEPRECATED. Use --outFile instead.

Documentation of --outFile option:

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

like image 93
Alex Filatov Avatar answered Nov 12 '22 23:11

Alex Filatov


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

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

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

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

like image 42
Jeffery Grajkowski Avatar answered Nov 12 '22 23:11

Jeffery Grajkowski