Setup a Typescript project with classes shared bet

2019-05-10 01:02发布

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

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

How to do that ?

PS: for those how know GWT, what I want is similar to the shared project.

2条回答
Emotional °昔
2楼-- · 2019-05-10 01:13

I managed to do it this way :

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

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

Autocompletion works, F12 too...

查看更多
狗以群分
3楼-- · 2019-05-10 01:28

If you use an external build tool e.g grunt-ts its easier. For a demo check out : https://github.com/basarat/demo-fullstack

With a sample gruntfile (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];
查看更多
登录 后发表回答