Javascript 有角度的2-ng构建

Javascript 有角度的2-ng构建,javascript,node.js,angular,typescript,angular-cli,Javascript,Node.js,Angular,Typescript,Angular Cli,因此,我需要创建一个无需运行服务器即可工作的构建 运行ng build。获取了一个dist文件夹 当我运行index.html时,我得到一个错误,如 GETfile:///D:/inline.bundle.js net::找不到错误文件 他正在我的D://驱动器的根目录中搜索js文件,而不是在项目文件夹中 好的,我从我的index.html中删除了一个,得到了这个错误: Unhandled Promise rejection: No base href set. Please provide a

因此,我需要创建一个无需运行服务器即可工作的构建

运行
ng build
。获取了一个
dist
文件夹

当我运行
index.html
时,我得到一个错误,如

GETfile:///D:/inline.bundle.js net::找不到错误文件

他正在我的D://驱动器的根目录中搜索
js
文件,而不是在项目文件夹中

好的,我从我的
index.html
中删除了一个
,得到了这个错误:

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>]
未处理的承诺拒绝:未设置基本href。请为APP_BASE_HREF标记提供一个值,或向文档中添加一个BASE元素;区域:;任务:承诺;值:ZoneAwareError{{uuuuuuuuuuuuuuuuuuuuuuuuuu区域符号\uuuuuuuuuuu错误:错误:无基本href集。请为APP\u基本href令牌提供一个值,或将基本元素添加到…,\uuuuuuuuuuuu区域符号\uuuuuuuuuuuuuuuuuuuu堆栈:“错误:无基本href集。请为…testing1/dist/vendor.bundle.js:28631:62)[],\uuuuuuuuuuu“未设置基本href。请为a…href标记提供值或向文档中添加基本元素。”}错误:未设置基本href。请为APP_base_href标记提供值或向文档中添加基本元素。
在新的路径定位策略(file:///D:/angular/testing1/dist/vendor.bundle.js:66150:19)[角度]
在provideLocationStrategy(file:///D:/angular/testing1/dist/vendor.bundle.js:62944:9)[角度]
在AppModuleInjector.get(/AppModule/module.ngfactory.js:164:77)[角度]
在AppModuleInjector.get(/AppModule/module.ngfactory.js:169:84)[角度]
在AppModuleInjector.get(/AppModule/module.ngfactory.js:198:151)[角度]
在AppModuleInjector.createInternal(/AppModule/module.ngfactory.js:241:60)[角度]
在AppModuleInjector.NgModuleInjector.create(file:///D:/angular/testing1/dist/vendor.bundle.js:56323:76)[角度]
在NgModuleFactory.create(file:///D:/angular/testing1/dist/vendor.bundle.js:56291:18)[角度]
在file:///D:/angular/testing1/dist/vendor.bundle.js:38426:61 [角度]
在Object.onInvoke(file:///D:/angular/testing1/dist/vendor.bundle.js:28762:37)[角度]
在Zone.webpackJsonp.528.Zone.run(file:///D:/angular/testing1/dist/polyfills.bundle.js:2591:43)[=>角度]
在NgZone.run(file:///D:/angular/testing1/dist/vendor.bundle.js:28631:62) []
因此,如果没有
,则
angular2router
不起作用,并且
index.html
无法找到带有
的本地文件

如何解决它?

使用--base href和适当的base

从ng帮助构建:

--基本href(字符串)(默认值:/)
别名:-bh

你好,
与项目建设有关的问题2不可否认,例如:
[我的项目截图][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>
Quand j'exécute la commande ng build,兜售项目的资源,以实现“地区”和“区域”之间的相互转换。
当然,这是一份档案,它包含了一些变化无常的媒体和字体,它们是令人不安的“资产”,可以在档案的双重文本中追溯(请看副本)。
PAR的例子,Le FigHIER图像背面。
De plus,voici la config De angular-cli.json:
“风格”:[
“assets/css/main.css”,
“styles.css”,
...
]
一个问题。
示例:body{background:url(../img/back.jpg)};
谢谢你的帮助。
在基本href中添加“.”,如下所示:

<base href="./">


多亏了爱慕者的评论,这对我很有用。

在index.html中使用下面的脚本

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

文件。写入(“”)
让我知道它是否对您有效。

请放回去,但要用。
<script>
    document.write('<base href="' + String(document.location).replace('index.html','') + '">')
</script>