angular-cli
angular-cli copied to clipboard
Automatic relative baseUrl for prerendered pages (SSG)
Command
build
Description
If I want to build an angular app and benefit from prerendering (SSG) without using server-side rendering (SSR), I currently need to know where it will be deployed at build-time.
Describe the solution you'd like
I would like to enable an option where baseHref does not need to be specified explicitly. Instead, it should be calculated by the prerendering process for each page it processes.
This is the resulting baseHrefs I imagine for different routes:
- /index.html ->
<base href="./"> - /subpage/index.html ->
<base href="../"> - /subpage/subsubpage/index.html ->
<base href="../../">
and so on. The baseHref would simply insert as many ../ segments as the currently rendered route nesting level.
Describe alternatives you've considered
- I could disable prerendering (losing the performance benefits)
- I could disable routing in my app (losing functionality)
- Theoretically, I could switch to the hash-based navigation, but then I'd implicitly lose the ability to prerender
- I could postprocess the files depending on the deployment path, but that would be an extra build step
- I could run SSG in addition to SSG, to fix the baseHref while serving the files, but that would mean I need to deploy a Node.js backend instead of a simple web server like nginx or apache.