Set up a Typescript project with classes shared between client and server applications?

I currently have a solution with two projects. ServerApp (nodejs NTVS) and BrowserApp (Html ​​Typescript app).

I want to share classes between both projects and get immediate intellisense.

How to do it?

PS: for those who know GWT, what I want seems to be a generic project.

+3


source to share


2 answers


I managed to do it this way:

  • create a third project named SharedClasses (I used HTML Typescript template)
  • add my general classes to it
  • add shared_reference.ts file with links to these class files
  • add a reference to the reference.ts file in the ServerApp and BrowserApp projects that point to shared_reference.ts


/// <reference path="../SharedClasses/shared_reference.ts" />

Autocomplete works, F12 too ...

+3


source


If you are using an external build tool, for example grunt-ts

, this is easier. For a demo demonstration: https://github.com/basarat/demo-fullstack

With a sample grunt file ( https://github.com/basarat/demo-fullstack/blob/master/src/Gruntfile.js ). Important bit:



  var commonFiles = "common/**/*.ts";
  var serverFiles = ["server/**/*.ts", commonFiles];
  var clientFiles = ["client/**/*.ts", commonFiles];

      

0


source







All Articles