This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Configuring TypeScript Which Files to Compile with "Files" and "OutDir"

1:24 TypeScript lesson by

This lesson shows how to configure the .tsconfig so you only compile the .ts files you want. It then shows how to configure which directory you'd like to compile the files to using "outDir".


egghead.io comment guidelines

Avatar
egghead.io

This lesson shows how to configure the .tsconfig so you only compile the .ts files you want. It then shows how to configure which directory you'd like to compile the files to using "outDir".

A common scenario for many applications and libraries is to have something like a main entry file where we'll call this app. You basically start your app here and import everything into this TS file. For your tsconfig, what you do, instead of excluding all the node modules, you'd tell it explicitly what you want to include in files.

Let's say I want to include main.ts. I'm also going to come in here and say I want to output the files into an OutDir of dist. Now, when I run tsc, it will take the main.ts, compile everything down into main.js.

If I were to create a new file and call it 2.ts, and we'll say class 2, and run tsc again, you'll see that this 2 class did not get compiled and included in my dist. If I want to include it, all I'd have to do is import 2.

Now, when I compile, because I told my main.ts to import this 2.ts, now 2.ts got compiled. My main required or used whatever module definition is defined in your module settings here.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?