4

Now I am trying to build angular2 project with --base-href option, But it is not working well.

ng build --bh=/Chamber/frontend/

This is contents of .angular-cli.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "frontend"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "D:/Work/Learn/Laravel/Chamber/Chamber/public/frontend/",
      "assets": [
        "assets",
        "assets/favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
          "../node_modules/bootstrap/dist/css/bootstrap.min.css",
          "../node_modules/font-awesome/scss/font-awesome.scss",
          "styles.scss"
      ],
      "scripts": [
          "../node_modules/jquery/dist/jquery.min.js",
          "../node_modules/bootstrap/dist/js/bootstrap.min.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.dev.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json"
    },
    {
      "project": "src/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "component": {}
  }
}

After building, the outDir's index.html contains not valid basehref as below.

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

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
</head>

<body class="homepage">
  <app-root>Loading...</app-root>

<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="scripts.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
</html>

This is my angular2 version.

D:\Work\Learn\Laravel\Chamber\Frontend>ng -v
Your global Angular CLI version (1.0.3) is greater than your local
version (1.0.1). The local Angular CLI version is used.

To disable this warning use "ng set --global warnings.versionMismatch=false".
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.0.1
node: 6.10.0
os: win32 x64
@angular/common: 4.1.0
@angular/compiler: 4.1.0
@angular/core: 4.1.0
@angular/forms: 4.1.0
@angular/http: 4.0.3
@angular/platform-browser: 4.1.0
@angular/platform-browser-dynamic: 4.1.0
@angular/router: 4.1.0
@angular/cli: 1.0.1
@angular/compiler-cli: 4.1.0

D:\Work\Learn\Laravel\Chamber\Frontend>

I don't know what is wrong. Is there anyone to fix this?

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
LarAng
  • 1,255
  • 3
  • 18
  • 28
  • Which version of Angular and the CLI? Run `ng -v` and provide the output. – jonrsharpe May 21 '17 at 15:49
  • Thanks for your care. I will attach ng -v result as my answer (because of comment length is short) – LarAng May 21 '17 at 15:56
  • Have you tried to create new dummy project with angular cli and built it with `ng build --bh xxx`? If it did not work, this means problem is not project specific. – ulubeyn May 21 '17 at 16:10
  • Thanks. I will try with dummy project. – LarAng May 21 '17 at 16:14
  • @ulubeyn, new dummy project is built with correct base href. It's base href changed well. Then what's the reason. How can I fix it? – LarAng May 21 '17 at 17:06
  • @ulubeyn, I appreciate your efforts. I've already accept your answer. Thanks! – LarAng May 21 '17 at 17:47

1 Answers1

5

There is typo in your html, this is the reason. Change <base href= "/"> to <base href="/">.

ulubeyn
  • 2,761
  • 1
  • 18
  • 29