Use TypeScript in ASP.NET MVC

How to effectively use TypeScript with ASP.NET MVC?

I want my IDE to do the following when starting my project:

  • Compile (interpret) my TypeScript files (* .ts) with the TypeScript compiler.
  • Collapse all javascript files.
  • Obviously, run my application :).

How to configure the IDE to automatically complete all the steps at startup?

+7
source share
1 answer

At this address, you will find that the current TypeScript preview version does not provide a project template for an ASP.NET MVC 4 project. But you can edit the csproject file with the following code:

<ItemGroup> <TypeScriptCompile Include="$(ProjectDir)\**\*.ts" /> </ItemGroup> <Target Name="BeforeBuild"> <Exec Command="&amp;quot;$(PROGRAMFILES)\ Microsoft SDKs\TypeScript\0.8.0.0\tsc&amp;quot; @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" /> </Target> 

It allows you to compile all TypeScript when creating an ASP.NET MVC 4 project.

About optimization:

I suggest that you separate the JavaScript files of your project and add links to their home page, for example, to this post: How can I automatically compress and minimize JavaScript files in an ASP.NET MVC application? .

You can also use bundling with a Razor view. Personally, I use this and it works great.

+6
source

All Articles