Angular 5 Universal: Using server.ts in Development

I used the new Angular Universal Starter to start a new Angular 5 project. For the new release they only give the Angular CLI version as a starter. Everything works fine and I can run my project in production with npm run serve:ssr etc.

But: I have a custom API for the node.js/express server that acts as a wrapper for my backend.

When starting the project in development with ng serve or npm run start I have a working Angular application with automatic reload on file changes etc. Unfortunately in development the server.ts file is ignored, so my API wrapper is not available.

So did anyone get the new Angular Starter Kit up and running with the server.ts file used in development?


As of now angular cli does not support universal to run in dev mode. You can try nodemon if watching changes is what you need:

nodemon --ignore dist -e ts --exec 'npm run build:ssr && npm run serve:ssr'

It will restart every time you change a .ts file, but it will build the whole application again, so it is not fast.


On Github FriOne mentioned a better workaround using ts-node-dev :

ts-node-dev --fast --respawn server.dev.ts

To run this I duplicated the server.ts file to server.dev.ts only with the APIs I need to access while in dev. this way you can use ng serve for fast rebuilds while developing and still access your node-apis.

链接地址: http://www.djcxy.com/p/31342.html

上一篇: 无法启动服务器

下一篇: Angular 5 Universal:在开发中使用server.ts