1

Is there a way to setup a "BeforeBuild" step that compiles each TypeScript file to its own Javascript file in a specific directory? For instance, I would like all TypeScript files to compile to a individual Javascript files in the '\tsbuild' directory in the solution.

Right now the compiler is combining all of the TypeScript files into one Javascript file in a specified directory - which looks like this:

  <Target Name="BeforeBuild">
    <Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; --out @(TypeScriptCompile ->'&quot;$(ProjectDir)tsbuild\buildall.js&quot; &quot;%(fullpath)&quot; ', ' ')" />
  </Target>

Then, once they are in one directory, the goal is to configure the Bundle Configuration to pick them up and minify them during release. The other purpose is to help troubleshooting during development.

joelmdev
  • 11,083
  • 10
  • 65
  • 89
anAgent
  • 2,550
  • 24
  • 34

2 Answers2

3

Once 0.8.2.0 is released (soon!) you'll be able to pass a directory to --out to get the desired behavior. For now, there isn't a particularly elegant way to do this.

Ryan Cavanaugh
  • 209,514
  • 56
  • 272
  • 235
  • Will the [comment preservation problems](http://stackoverflow.com/a/14206006/390407) be fixed in 0.8.2.0? Or any rough idea of how long that might take to fix? I'm sure its low on the priority list. – ryan Jan 18 '13 at 19:56
  • Comment preservation will get a bit better in 0.8.2.0, but when the new parser comes online in a later release, it will be vastly improved (our goal is that vanilla JS would compile with identical formatting/comments). – Ryan Cavanaugh Jan 19 '13 at 00:00
2

With the release of TypeScript 0.8.2, there is some build changes that I made that I now have it working the way I want.

For more information the Compile and Save, check out: http://typescript.codeplex.com/wikipage?title=Compile-on-Save

First I modified my *.csproj, adding:

  <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptIncludeComments>true</TypeScriptIncludeComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptIncludeComments>false</TypeScriptIncludeComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
  </PropertyGroup>
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" />

Then, I created a post build step that copies my files using this Post https://stackoverflow.com/a/585188/1220302

Adding this to a post build

for /R "$(ProjectDir)modules\" %%f in (*.js, *.map) do copy %%f "$(ProjectDir)build\"

I hope that helps someone.. =)

Community
  • 1
  • 1
anAgent
  • 2,550
  • 24
  • 34