Angular 2 CLI项目在部署时无法加载资源

问题描述 投票:1回答:2

我的机器和开发环境是:Mac 10.11.4 angular-cli:1.0.0-beta.10 node:5.11.1 os:darwin x64

该项目是从Angular CLI创建的。运行'ng serve --prod'时应用程序运行正常,但是当我运行'ng build --prod'然后发布直播时,我可以发现很多错误,无法找到资源。

enter image description here

在index.html中加载这些资源有很多“魔力”,所以我不知道如何解决这个问题....

https://github.com/JimTheMan/Safe-Foods/tree/gh-pages

我的项目名为“SafeFoods”。正确的路径,例如es6-shim.js,应该是:https://jimtheman.github.io/Safe-Foods/vendor/es6-shim/es6-shim.js实际上是:https://jimtheman.github.io/vendor/es6-shim/es6-shim.js

ng build任务每次都会这样创建它所以我不确定如何告诉它正确的路径......

注意:我也尝试将angular-cli更新到最新版本并使用'--base-href',但这似乎没有正常运行:

SafeFoods(gh-pages)buildng build --prod --base-href / Safe-Foods /

选项'--base-href'未在build命令中注册。运行build --help以获取支持的选项列表。

任何帮助表示赞赏。谢谢。

angular web-deployment github-pages angular-cli
2个回答
1
投票

config/environment.js设置baseURL: '/Safe-Foods'

src/index.html设置<base href="{{ baseURL }}">


1
投票

我已经回答了一个非常相似的问题here

你在找

--deploy-url /Safe-Foods

我希望能回答你的问题!

© www.soinside.com 2019 - 2024. All rights reserved.