我的机器和开发环境是: 苹果电脑10.11.4 Angular -cli:1.0.0-beta.10 节点:5.11.1 操作系统: Darwin x64
该项目是从 Angular CLI 创建的。该应用程序在运行“ngserve --prod”时工作正常,但是当我运行“ng build --prod”然后实时发布时,我会出现大量找不到资源的错误。
在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 构建任务每次都会这样创建它,所以我不确定如何告诉它正确的路径...
注意:我还尝试将 angular-cli 更新到最新版本并使用“--base-href”,但这似乎无法正常运行:
SafeFoods (gh-pages) ♔ ng build --prod --base-href/Safe-Foods/
选项“--base-href”未在构建命令中注册。运行 build --help 以获取受支持选项的列表。
感谢任何帮助。谢谢。
最佳答案
在 config/environment.js
设置baseURL: '/Safe-Foods'
.
在 src/index.html
设置<base href="{{ baseURL }}">
.
关于Angular 2 CLI 项目在部署时无法加载资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39334259/