angular-nx-ssr
angular-nx-ssr copied to clipboard
File structure problem when second app is added (I think)
I really appreciate that you put this example up!
Correct me if I'm wrong, but the current setup will fail when someone adds a second app to their project. At that point, there will be two server configurations but only one top level server.ts file. Things will need to be renamed / modified.
My solution...
Your example folder:
root
. . .
dist
- apps
- web
- server
server.ts
tsconfig.server.json
webpack.server.config.js
My example folder:
root
. . .
. . .
dist
- apps
- web
- browser
- server
servers
- web
- server.ts
- webpack.server.config.js
tsconfig.web-server.json
. . .
. . .
Then, when a second project is added, the folder will look like
root
. . .
. . .
dist
- apps
- web
- browser
- server
- second_web
- browser
- server
servers
- web
- server.ts
- webpack.server.config.js
- second_web
- server.ts
- webpack.server.config.js
tsconfig.web-server.json
tsconfig.second_web-server.json
. . .
. . .
Hi @thefliik, thanks for your comments.
You are right, the current setup does not take into account that you can have multiple apps. At this point I don't think I will be adding support for it, but feel free to send in a PR that does that.
I think the project can still just have 1 server.ts and webpack.server.config.js, I think the best approach would be to make some of these paths depend on ENV vars, mainly:
https://github.com/beeman/angular-nx-ssr/blob/master/server.ts#L20
and
https://github.com/beeman/angular-nx-ssr/blob/master/webpack.server.config.js#L11
That would allow the output paths to be set when running the postbuild step from package.json.
I would really like this project to be a simple example, so I can't promise I will land support for it. Hope you understand :-)
Interesting! I am/was under the impression that the only reason to use nrwl/nx is to support creating multiple applications with shared (custom/private) libraries. Making it less of a question of if someone will add a second app, then when someone will add a second app. This being said, your example definitely stands up as is: I was able to convert it to my needs pretty easily and I don't think I would have even attempted using nrwl/nx with ssr if I hadn't stumbled across this repo!
Your suggestion to use ENV vars with the build scripts (or any script option / argument, really) to modify the output definitely seems like a better strategy. Initially, I wasn't convinced that I was going to get ssr with multiple apps working at all, so I wasn't interested in spending a lot of time polishing my solution. Now that it is working though, at some point I'll revisit it and polish it up. I'll definitely send along a PR at that time.
As much as a suggestion for you, I figured anyone else adopting this starter with the goal of supporting multiple apps might be curious how someone else got things working and having this issue up might provide some direction for them.