What would be the best way to build this

Topics: General
Sep 28, 2013 at 12:39 PM
Hello, i have a little question.

My Typescript project looks like this:

-Core.ts

-App1.ts
--App1_class_1.ts
--App1_class_2.ts
--App1_class_3.ts

-App2.ts
--App2_class_1.ts
--App2_class_2.ts
--App2_class_3.ts

How should work in the browser: The core loads the javascript files for App1 and App2 only when needed. It will also create a new instance of the App1 or the App2 after the file has been loaded and execute some of the functions on the instance. The App1 and App2 will also use some functionality of the Core.

With the tsc i managed to compile 1 big javascript file, but that's not really what i need. Is there any possible way i easely can compile a seperate Core.js, App1.js and App2.js without losing the type information/code hinting in the .ts files?
Coordinator
Sep 28, 2013 at 10:07 PM
When you compile each of your 3 projects, generate a declaration file for it with the "-d" switch. This will generate a .d.ts which describes the types in the compiled code. In the other projects reference this .d.ts file, not that actual implementation files from the alternate project. I believe this should achieve what you want.
Sep 29, 2013 at 11:11 AM
I will try that, thanks!
Oct 3, 2013 at 6:08 PM
Is there any story for this with compile on save? For example is there a good way to get save to not only generate the .js and .map files, but also the .d.ts file?
Coordinator
Oct 4, 2013 at 9:39 PM
We don't yet have the configuration settings for compile-on-save. For now, the compile-on-save just uses the default settings.
Oct 12, 2013 at 11:51 AM
Edited Oct 12, 2013 at 11:52 AM
If anyone wants the project config:


Core:
  <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptRemoveComments>false</TypeScriptRemoveComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
    <TypeScriptModuleKind>CommonJS</TypeScriptModuleKind>
    <TypeScriptGeneratesDeclarations>true</TypeScriptGeneratesDeclarations>
    <TypeScriptOutFile>bin\main.js</TypeScriptOutFile>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptRemoveComments>true</TypeScriptRemoveComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
    <TypeScriptModuleKind>CommonJS</TypeScriptModuleKind>
    <TypeScriptGeneratesDeclarations>true</TypeScriptGeneratesDeclarations>
    <TypeScriptOutFile>bin\main.js</TypeScriptOutFile>
  </PropertyGroup>
  <Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
  
  <Target Name="AfterBuild">
     <Copy SourceFiles="bin\main.d.ts" DestinationFolder="..\App1\" ContinueOnError="false" />
  </Target>
App1:
  <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptRemoveComments>false</TypeScriptRemoveComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
    <TypeScriptModuleKind>CommonJS</TypeScriptModuleKind>
    <TypeScriptGeneratesDeclarations>true</TypeScriptGeneratesDeclarations>
    <TypeScriptOutFile>bin\scripts.js</TypeScriptOutFile>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptRemoveComments>true</TypeScriptRemoveComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
    <TypeScriptModuleKind>CommonJS</TypeScriptModuleKind>
    <TypeScriptGeneratesDeclarations>true</TypeScriptGeneratesDeclarations>
    <TypeScriptOutFile>bin\scripts.js</TypeScriptOutFile>
  </PropertyGroup>
  <Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
     <Copy SourceFiles="bin\scripts.js" DestinationFolder="..\Core\" ContinueOnError="false" />
     <Copy SourceFiles="bin\scripts.d.ts" DestinationFolder="..\Core\" ContinueOnError="false" />
  </Target>