2017-02-22 16 views
2

私はサーバーを実行せずに動作できるビルドを作成する必要があります。角度2 ngのビルド

実行ng builddistフォルダがあります。

私は私のDのルートでjsファイルことを彼が探している

GET file:///D:/inline.bundle.js net::ERR_FILE_NOT_FOUND

のようなエラーを取得index.htmlイムを実行します://ドライブではなく、プロジェクトフォルダ内

ので大丈夫、私は私のindex.htmlから<base href="/">を取り出して、このエラーを得た:

Unhandled Promise rejection: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document. ; Zone: <root> ; Task: Promise.then ; Value: ZoneAwareError {__zone_symbol__error: Error: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to…, __zone_symbol__stack: "Error: No base href set. Please provide a value fo…testing1/dist/vendor.bundle.js:28631:62) [<root>]", __zone_symbol__message: "No base href set. Please provide a value for the A…HREF token or add a base element to the document."} Error: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document. 
at new PathLocationStrategy (file:///D:/angular/testing1/dist/vendor.bundle.js:66150:19) [angular] 
at provideLocationStrategy (file:///D:/angular/testing1/dist/vendor.bundle.js:62944:9) [angular] 
at AppModuleInjector.get (/AppModule/module.ngfactory.js:164:77) [angular] 
at AppModuleInjector.get (/AppModule/module.ngfactory.js:169:84) [angular] 
at AppModuleInjector.get (/AppModule/module.ngfactory.js:198:151) [angular] 
at AppModuleInjector.createInternal (/AppModule/module.ngfactory.js:241:60) [angular] 
at AppModuleInjector.NgModuleInjector.create (file:///D:/angular/testing1/dist/vendor.bundle.js:56323:76) [angular] 
at NgModuleFactory.create (file:///D:/angular/testing1/dist/vendor.bundle.js:56291:18) [angular] 
at file:///D:/angular/testing1/dist/vendor.bundle.js:38426:61 [angular] 
at Object.onInvoke (file:///D:/angular/testing1/dist/vendor.bundle.js:28762:37) [angular] 
at Zone.webpackJsonp.528.Zone.run (file:///D:/angular/testing1/dist/polyfills.bundle.js:2591:43) [<root> => angular] 
at NgZone.run (file:///D:/angular/testing1/dist/vendor.bundle.js:28631:62) [<root>] 

だから、<base>index.htmlなしangular2router doesntの仕事は、私はそれを解決するにはどうすればよい<base>

と私のローカルファイルを見つけることができませんか? ngのヘルプビルドから適切なベース

+0

を置きます。 –

答えて

0

使用--base-HREF:

--base-href (String) (Default: /)
aliases: -bh

0
Bonjour, 

<div>Ma question concerne ng build d'un projet angular 2 dont voici un exemple : 

[私のプロジェクトのスクリーンショット] [1]

Quand j'exécute la commande ng build, toutes les ressources de mon projet sont transférées dans le répertoire "dist", donc normale jusque là. 
Cependant, dans ce dossier, je constate que certains de mes fichiers media et fonts qui se trouvent dans "assets", se retrouve en double à l’extérieur de ce dossier (Voir copie écran ci-dessous). 
Par exemple, le fichier image back.jpg qui est rangé dans ponyracing/dist/assets/img/back.jpg, se retrouve en double à l’extérieur dans ponyracing/dist/back.jpg 

De plus, voici la config de angular-cli.json : 

"styles": [ 
    "assets/css/main.css", 
    "styles.css", 
    ... 
] 

Ma question est de savoir si ce problème de fichiers doubles est causé par mon fichier main.css externe que j’ai rangé dans ponyracing/dist/assets/css/main.css et que dans ce fichier, le path des images est relatif au dossier ponyracing/dist/assets/img ? 

Exemple : body { background: url(../img/back.jpg) }; 

Merci pour votre aide.</div> 
0

"。"を追加してください。

<base href="./"> 

Admirのコメントのおかげで、これは私のために働いていました。

0

下記のスクリプトをindex.htmlで使用してください。

<script> 
    document.write('<base href="' + String(document.location).replace('index.html','') + '">') 
</script> 

私はそれがあなたのために働くかどうかをお知らせください。