18

How do I tell the TypeScript compiler to generate amd modules (--module amd) from within Visual Studio.

Thanks.

MBeckius
  • 1,447
  • 2
  • 12
  • 14

3 Answers3

9

In your project file you will need to change the MSBuild target that is building TypeScript files. If you are using the default template for "HTML Application built with TypeScript", unload your project, edit the project file, you will find a target called "BeforeBuild" that is calling the compiler at "$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc", add --module amd to it; save and reload your project. next time you build you should see the command argument passed correctly to the compiler.

mohamed hegazy
  • 9,191
  • 4
  • 30
  • 21
  • 2
    It looks like they've added an option to configure this, either in TS 0.8.1 or as part of Web Essentials. Open Tools->Options and look under Web Essentials->TypeScript. – Morten Mertner Dec 03 '12 at 22:54
  • 8
    @MortenMertner - and now they've removed it again. Wouldn't want to make this too easy now, would we? – Daniel Earwicker Feb 15 '14 at 11:55
8

On the latest Visual Studio 2013 Update 3 + WebEssentials the options are now (finally) properly moved in the Project Options Pane (Right click on the project -> Options -> TypeScript Build pane).

MadLux
  • 81
  • 1
  • 2
  • 1
    Yes, VS2013 update 3 now has a TypeScript Build tab in the project properties, but checking "Combine JavaScript output into file" doesn't change the tsc command line at all. – dthorpe Aug 14 '14 at 19:37
5

Becouse this problem is still actual even for TS 1.0 and WebEssentials for VS 2013 Update 3, check this solution here: http://icanmakethiswork.blogspot.com/2014/02/typescript-and-requirejs-keep-it-simple.html Or shortly:

1) Open project file.

2) find this lines:

  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />

3)Insert this lines before:

    <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptModuleKind>amd</TypeScriptModuleKind>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptModuleKind>amd</TypeScriptModuleKind>
  </PropertyGroup>
Oleksandr Papchenko
  • 2,071
  • 21
  • 30
  • 1
    Nice trick! If you intend to use `amd` for both `Debug` and `Release` you don't need to specify a condition and you don't need two property groups. You'll there's a element called `TypeScriptToolsVersion` you can add the `TypeScriptModuleKind` directly after that, it works just fine. This is really nice since it now is part of your project configuration. It does not require changing the global environment on the host machine (which modifying targets files would). – John Leidegren Jan 07 '15 at 20:46