TypeScript - compile all ts files to one js

9 points
Created by:

In TypeScript it is possible to compile all *.ts files to one *.js file in following way.

Download all source code from one place here.

1. outFile property example

tsconfig.json file:

    "version" : "3.0.3",
    "compilerOptions" : {
        "module" : "amd",
        "removeComments" : true,
        "outFile" : "./out.js",
        "baseUrl" : "./",
        "sourceMap" : true,
        "alwaysStrict" : true,
        "declaration" : true,
    "include": [
    "exclude": [

Note: "outFile" : "./out.js" defines single source code output file.


Person.ts file:

export class Person
	public constructor(public name : string, public age : number)
		// nothing here ...
	public toString() : string
		return `{ Name: ${this->name}, Age: ${this->age} }`;

Printer.ts file:

import { Person } from "./Person";

export class Printer
	public static printPerson(person : Person) : void
	public static printPersons(persons : Array<Person>) : void
		for(let entry of persons)

Main.ts file:

import { Person } from "./Person";
import { Printer } from "./Printer";

let persons = new Array<Person>();

persons.push(new Person('John', 30));
persons.push(new Person('Adam', 23));
persons.push(new Person('Kate', 41));


index.htm file:

<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <meta name="description" content="Example typescript files compilation to single javascript file.">
  <meta name="author" content="">
  <script src=""></script>
  <script src=""></script>
  <script src="out.js"></script>
    require( [ 'Main' ] );

Note: above source code uses modules loader.


Compilation and running:

  1. Open console (e.g. Bash)
  2. Go to project directory
  3. Run tsc program to compile all files to one
  4. Open index.htm in web browser


Bash console preview:

$ cd /C/Project
$ tsc


/C/Project directory preview:


  • after tsc command run three new files (out.*) should appear.
  • out.d.ts contains all declarations (useful for intellisense and intengration out.js file with other typescript projects)
  • contains development mapping for debug process
  • out.js contains all sourcecode transpiled to single javascript¬†file


Web browser preview: 


Download all source code from one place here.

2. Troubleshooting

3. References

  1. RequireJS - Home Page
  2. tsconfig.json - TypeScript Docs

Hey ūüĎč
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.