Setup a Typescript project with classes shared between client and server apps?

孤者浪人 提交于 2019-12-06 02:46:52

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...

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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!