I am using Angular CLI to build my Angular 4 project. I have a requirement to run the application
- as a standalone application
- as an application embedded in a portal page
The application runs well as a standalone app.
When embedded in a portal whose static content is served from a CDN, the resources that are loaded using relative URLs do not get loaded as they are nested under a different root directory under the CDN.
e.g. In my standalone app, I have a background image that I refer in my scss file as background: url('/assets/images/bg.jpg'). However, when embedded in portal, the relative URL is /cdn/app/assets/images/bg.jpg.
Is there a way to change the relative URLs used in SCSS and HTMLs as part of ng build ? Can I define a variable that holds my CDN path and Angular-CLI replaces the variable with the actual value at build time?
e.g.
background: url('$cdnAppRoot/assets/images/bg.jpg');
replaced with
background: url('/cdn/app/assets/images/bg.jpg')