Using tsc command it's as easy as running:
tsc --out all.js js/*.ts
How can I configure Visual Studio to do that when I build my project?
Explanation: tsc: It stands for TypeScript compiler which is used to invoke the compiler in order to compile the TypeScript files. –out: It is a CLI (Command Line Interface) command which concatenates the TypeScript files and emits the output to a single JS file. outputFile.
Can we combine multiple . ts files into a single . js file? Yes, we can combine multiple files.
The TypeScript compiler supports a mix of JavaScript and TypeScript files if we use the compiler option --allowJs : TypeScript files are compiled. JavaScript files are simply copied over to the output directory (after a few simple type checks).
I've found a potentially easier solution by just modifying the build properties of the project (.csproj / .vbproj) you are building:
I'm unsure which version of Typescript that this feature was introduced in. But it seems a much simpler method than the svallory's solution
Source: http://rostacik.net/2013/12/18/how-to-setup-post-build-event-in-visual-studio-to-combine-multiple-typescript-files-to-one-javascript-file/
EDIT: Since Visual Studio 2015, it's now very easy to integrate Grunt/Gulp tasks and have them run in your builds. I've personally be really enjoying using Gulp for more granular control over what files I build and/or minify, and I highly recommend it. Using this guide as a starting point should help.
Just got it. Add this line:
<Exec Command="tsc --out all.js @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
to the BeforeBuild
target of your .csproj
or .vbproj
file, like this:
<Target Name="BeforeBuild">
<Message Text="Compiling TypeScript files" />
<Message Text="Executing tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
<Exec Command="tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
<Exec Command="tsc --out all.js @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
</Target>
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