6

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?

3 Answers 3

3

I've found a potentially easier solution by just modifying the build properties of the project (.csproj / .vbproj) you are building:

Project Build Typescript Settings

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Just got it. Add this line:

<Exec Command="tsc --out all.js @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />

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 ->'&quot;%(fullpath)&quot;', ' ')" />
    <Exec Command="tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
    <Exec Command="tsc --out all.js @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
</Target>

5 Comments

You almost certainly don't want to invoke tsc twice like you're doing here (for one, source maps won't work, also it'll take twice as long). Just modify the existing Exec element to include the --out parameter.
I know it'll take twice as long, but I think it's better than have to modify the build so I can test if everything went fine all the way to the minified script. Source maps are only being generated for the individual file compilation (which I use for debugging). Can you explain to me why source maps won't work?
When I try this I get an error loading the project: The project file could not be loaded. An XML comment cannot contain '--', and '-' cannot be the last character...
@Grinn It appears to me that you put that line inside an xml comment. (<!-- .. -->) Paste your file to a gist, or publish it somewhere else, and link it here so I can help you more.
@svallory: How silly of me. It was in a comment. I was using Notepad++ to edit the .csproj file (no colorization), and didn't notice that the section was commented out.
1

It seems that the proposed solution is for typescript 0.8.1.1 and not 0.8.2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.