防止构建将base href放入index.html

时间:2018-02-23 12:50:03

标签: angular

进行构建时:

ng build --prod --aot=false

它始终在dist文件夹的index.html中放入<base href>。有没有办法阻止这个?

1 个答案:

答案 0 :(得分:2)

要忘记<base href="/">上的index.html,请将其从src/index.html文件中删除:

<!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>
...

应该是,然后:

<!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>
...


ng build --base-href标志

重要的是要注意ng build命令has a --base-href (or --bh) flag,但它只适用于更改href属性(如果存在)或添加它(如果它没有&#39;}存在)。 It doesn't allow you to remove it