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?
Open a terminal and run tsc -w , it'll compile any . ts file in src directory into . js and store them in ts-built directory.
When you run tsc command in a directory, TypeScript compiler looks for the tsconfig. json file in the current directory and if it doesn't find one, then it keeps looking up the directory tree until it finds one. The directory where the tsconfig. json is located is considered as the root of the project.
Here, you will learn how to compile a TypeScript project and also learn about tsconfig. json. As you know, TypeScript files can be compiled using the tsc <file name>. ts command.
You can find the complete code for tsconfig. json below. Another way of automating the TypeScript compilation is by using command line interface or the Command Prompt. The second way is pretty simple to achieve; we just need to write a single line to watch any changes in our TypeScript file.
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.
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 @ts-files.txt --out ..\output\deerchao.web.js --removeComments
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With