Andrew Howard
Andrew Howard

Reputation: 3092

Prevent build from putting in base href into index.html

When doing a build:

ng build --prod --aot=false

It always puts in a <base href> in the index.html in the dist folder. Is there a way I can prevent this?

Upvotes: 1

Views: 849

Answers (1)

acdcjunior
acdcjunior

Reputation: 135792

To not get <base href="/"> on the dist index.html, remove it from the src/index.html file:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>PROJECTNAME</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
...

Should be, then:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>PROJECTNAME</title>

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
...


The ng build --base-href flag

It is important to notice that the ng build command has a --base-href (or --bh) flag, but it only works for changing the href attribute (if it exists) or adding it (if it doesn't exist). It doesn't allow you to remove it.

Upvotes: 3

Related Questions