2017-05-21 2 views
2

Jetzt versuche ich mit der Option --base-href ein angular2-Projekt zu erstellen, aber es funktioniert nicht gut.Angular2 warum die Option --base-href build funktioniert nicht

ng build --bh =/Kammer/Frontend/

Dies ist Inhalt .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": {} 
    } 
} 

Nach dem Bau enthält die OutDir der index.html nicht Gültiges Baseref wie unten.

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

Dies ist meine 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> 

Ich weiß nicht, was falsch ist. Gibt es jemanden, der das beheben kann?

+0

Welche Version von Angular und der CLI? Führen Sie 'ng -v' aus und geben Sie die Ausgabe an. – jonrsharpe

+0

Danke für Ihre Pflege. Ich werde ng -v Ergebnis als meine Antwort anhängen (wegen Kommentarlänge ist kurz) – Alex

+0

Haben Sie versucht, neue Dummy-Projekt mit eckigen CLI erstellen und baute es mit 'ng build --bh xxx'? Wenn es nicht funktionierte, bedeutet dies, dass das Problem nicht projektspezifisch ist. – ulubeyn

Antwort

4

Es gibt Tippfehler in Ihrem HTML, das ist der Grund. Ändern Sie <base href= "/"> zu <base href="/">.

+0

Danke für Ihre Mühe. Das ist die richtige Antwort! – Alex

+1

OMG ... Ich habe das Gefühl, dass ich ohne diese Antwort Stunden mit einem ähnlichen Problem verschwendet hätte. –

+1

Ich hatte das gleiche Problem, ich benutzte Ticks '' und es würde nicht funktionieren, bis ich es zu "", ', dank @ulubeyn – Flea