Reputation: 19817
Is there any way how to compile TypeScript source files into single JavaScript bundle file?
We've build tool on node.js and TypeScript compilation is performed by
var ts = require('typescript');
...
var program = ts.createProgram(this.getAllInputFileNames(), this.typeScriptOptions, host);
var output = program.emit();
Currently, the typeScriptOptions
is:
{ target: 1, module: 2 }
I was trying to add out
into the typeScriptOptions
so it was
{ target: 1, module: 2, out: 'bundle.js' }
But no luck, the compiler still generates a lot of .js files ...
What option is needed to force TypeScript compiler to compile all input .ts files into single file?
EDIT:
With the above options the compiler generates a lot of .js
files as described above. Also bundle.js
is created but it is empty file.
Upvotes: 4
Views: 4624
Reputation: 64953
tsc
is a compiler/transpiler of TypeScript code into JavaScript and that's it. Sure it has some options in terms of the output of what it produces but essentially its job is to create output JavaScript.
What you do with it from there is up to you.
My suggestion to bundle things up is to use browserify to bundle your code.
In short, run it pointing at your outputted JavaScript main file and supply an output bundle file and it will create a single bundle file with all the JavaScript in the appropriate order based upon dependencies.
Upvotes: 3