Search code examples
angularangular-cli-v7

How to specify an absolute URL for generated chunk files in angular (CLI 7)


I'm having issues as I serve my javascript files from a CDN. IN new angular cli (v7) when I enable lazy loading the generated chunk files are loaded from the root directory by default, however I want them to be served from a different url (s3 in this case).

How it is being loaded:

...
http://<website_url>/polyfills.js
http://<website_url>/runtime.js
http://<website_url>/main.js
...

How I want it to load:

...
http://<website_url>/abolutepath/polyfills.js
http://<website_url>/abolutepath/runtime.js
http://<website_url>/abolutepath/main.js
...

Just to mention I have tried base href and it doesn't work. It still loads the chunk fiels from root.

<base href="/abolutepath/">

Solution

  • You can specify --deployUrl when using build

    ng build --prod --deployUrl http://<website_url>/abolutepath
    

    Basically this is when you upload files into custom folder + if want to use CDN