I recently added SSR to my Angular app with Angular Universal (with express as the server) and I'm having trouble updaing my build and deploy steps. I was using a dockerfile in which I was having a build step: ng build -c <environtmentName>
followed by a startup command CMD ["node", "./dist/MyApp/main.js"]
.
After adding SSR the new structure came with a couple of new commands in package.json, including one for "build": "build:ssr": "ng build --prod && ng run MyApp:server:production"
.
I am now trying to add a "pure" build script that would build both the frontend app plus the server related content, like server.ts.
I have noticed that if I run the ng build
command only the angular app is being built.
If I however run the build:ssr
command though it builds the app in the first part (ng build --prod
) and then it compiles and runs the server in the second ng run MyApp:server:production
I was not able to find a command that builds the server separately so that I can include it in my dockerfile. I do not want to run ng run MyApp:server:production
in my dockerfile, I simply want to run it as the CMD ["node", "./dist/MyApp/server/main.js"]
command for various reasons. The only workaround was to run the build:ssr
- or equivalent commands related to different environments I'm targeting - locally, then build the docker image, ng build simply ignores the express server related files it seems.