Angular-cli: [Question] How to set relative paths for scripts, styles, etc, injected to index.html

Created on 14 Dec 2016  路  6Comments  路  Source: angular/angular-cli

OS?

Ubuntu

Versions.

1.0.0-beta.17

My angular2 application, built with ng build --prod, is mounted to https://domain/app.
The problem is that scripts and styles injected in index.html have paths like src="styles.8e0edbbd6ad2cb36be49.bundle.js", so page is trying to look for them in root.
How to change it to src="./styles.8e0edbbd6ad2cb36be49.bundle.js"?
Thank you.

Most helpful comment

You can use 'ng build --prod --base-href /app/ ' to set the base href in the index.html to your directory.

All 6 comments

You can use 'ng build --prod --base-href /app/ ' to set the base href in the index.html to your directory.

In the <head> section of your index.html add the line:
<base href="/<base-folder>/">

That worked for me

--base-href parameter helped, thank you.

I'm using Angular 6, and setting --base-href wasn't enough to solve this, but setting deployUrl in angular.json did.

You can set it in projects -> $projectName -> architect -> build -> options.

E.g.
"deployUrl": "/app/"

Huge Thum

I'm using Angular 6, and setting --base-href wasn't enough to solve this, but setting deployUrl in angular.json did.

You can set it in projects -> $projectName -> architect -> build -> options.

E.g.
"deployUrl": "/app/"

Two thumbs way up! I spent the whole day trying to figure this out and I stumbled across your solution and it works great! Thank you very much for your assistance!

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings