How to generate a JavaScript bundle via the npm TypeScript compiler

Is there a way to compile the TypeScript source files into one javascript package file ?

We create tool for node.js and TypeScript, compilation is done

var ts = require('typescript');
...
var program = ts.createProgram(this.getAllInputFileNames(), this.typeScriptOptions, host);
var output = program.emit();

      

Currently typeScriptOptions

:

{ target: 1, module: 2 }

      

I tried to add out

to typeScriptOptions

, so it was

{ target: 1, module: 2, out: 'bundle.js' }

      

But no luck, the compiler still generates a lot of .js files ...

What parameter is required to force the TypeScript compiler to compile all input .ts files into one file?

EDIT:

With the above options, the compiler generates many files .js

as described above. Also created bundle.js

, but it's an empty file.

+3


source to share


1 answer


tsc

is a compiler / transpiler for TypeScript code to JavaScript and that's it. I'm sure it has some options in terms of outputting what it produces, but essentially its job is to create output JavaScript.

What you do with it is up to you.



My suggestion to link things up is to use browserify to link your code.

In short, run it pointing to your main JavaScript file and supply the output package file and it will create one package file with all the JavaScript in the proper order based on dependencies.

+3


source







All Articles