Sharing TypeScript classes between client and server

只愿长相守 提交于 2019-12-06 03:55:23

This is absolutely possible.

I have a project containing both SPA client application that runs in browser and server running in node.js that both share common typescript classes. For all of this I have just one tsconfig.json file (I am still not sure that this is the best approach but for now it works just fine)

Here are parts of my setup:

  • Use modules (previously called external modules). No need for namespaces and d.ts files for your own modules.
  • module = "commonjs" in tsconfig.
  • On client side use System.js as module loader (this will solve your 'Uncaught ReferenceError: exports is not defined'). You can use angular2 5 min quickstart as reference how to setup system.js.

It works like a charm.

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