If you run the following commands:
ng new --style=scss cli-universal-demo
You will see that ngc (@angular/compiler-cli) creates some files:
>On branch master
Those are the Ahead of Time (AOT) compiled files needed by the renderModuleFactory function
Contribute to cli-universal-demo development by creating an account on GitHub.github.com
At my repo I added the src/app/app.server.module.ts and the src/server.ts
After run ngc again, it will generate the src/app/app.server.module.ngfactory.ts file, with the AppServerModuleNgFactory needed to bootstrap our app on the server.
The renderModuleFactory function have 2 parameters:
1) Is the class generated by ngc, in our case AppServerModuleNgFactory
2) Some options needed:
- document: is a string with the content of our index.html file, I decided to use the index.html generated by ng build --prod, that comes with the scripts and style tags, I used readFileSync from the standard fs module from node to get the content of the index.hml file.
- url: used by the router, to render the right page if you are using routing, I used req.url from express.
The server.ts file, is just a express server that listens on port 4000 and serves our static files and the server side rendered pages.
Let me know if my explanation helped you, or if you still have some questions