15

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?

Alex Filatov
  • 2,232
  • 3
  • 32
  • 39
Vojtěch
  • 11,312
  • 31
  • 103
  • 173
  • Just FYI, using `--outFile` limits your module generation choices to **only "AMD" and "System"** per the doc: https://www.typescriptlang.org/docs/handbook/compiler-options.html – Jeff Ward Dec 13 '19 at 21:41

2 Answers2

10

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

Graham
  • 7,431
  • 18
  • 59
  • 84
Alex Filatov
  • 2,232
  • 3
  • 32
  • 39
7

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

Jeffery Grajkowski
  • 3,982
  • 20
  • 23
  • I think it's not a correct answer on a question. Question was Output to single file **without concatenation**. But here just list of --out commands – Alex Filatov Sep 26 '16 at 17:14
  • How do you get tsc to produce a flat build? By flat I mean one that doesn't have a dependancy on systemjs or requirejs? I'm trying to produce a lean build for npm. – Nikos Dec 19 '16 at 23:20
  • i was looking to compiled to a different directory and this answer solved my problem tsc -out output filea.ts – Umer Hayyat Sep 11 '17 at 06:49