Is it possible to compile a single TypeScript file into the output path using the tsc command?

In an attempt to separate the .ts source files from the .js output, I am trying to implement a formal file observer in TypeScript, and it seems that the ability to specify the output path for a single file does not exist.

Stream, just to be clear: I start looking at my entire src directory, making changes, say, src/views/HomeView.ts , and I want node to pick up the file that was changed, and move the compiled version to public/js/views/HomeView.js .

Using tsc myfile.ts --out myfile.js , it moves through all the modules and compiles each in the same path as the .ts file, without putting the final file in the correct path. However, it creates an empty file in which I would like it to end.

I am wondering:

1) Is it possible to use the --out and compile only one file? I do not want it to import and compile every single file, but just do syntax / error checking at compile time (and this is just a secondary requirement, not necessary); and

2) Is there a bug in the compiler that prevents it from combining / creating files correctly? Again, the end result in the path --out directive is empty, but the file is actually created.

Any help would be greatly appreciated.

* Update *

Although I do not want to close this question, since I believe this is still a problem, I went ahead and implemented the TypeScript core compiler to achieve what I needed to do, bypassing tsc in general. See https://github.com/damassi/TypeScript-Watcher for more information and usage.

+7
source share
1 answer

When you use the --out , you get one file with the compiler going through the dependencies and working out the correct order for the final file.

For example...

 tsc --out final.js app.ts 

Find any dependencies in app.ts and compile them too. Once it final.js out the correct order, it will save all the JavaScript in final.js . If this JavaScript file is empty, it usually indicates a compiler error.

You cannot use the --out to create a JavaScript file only for the TypeScript file you specify, unless that file has dependencies.

+3
source

All Articles