我已经使用 ember-cli 成功创建了一个小型应用程序。我尝试将它推送到我的 github repo 的 gh-pages 分支,但它在浏览器控制台中显示错误
Uncaught ReferenceError: require is not defined
加载 vendor.js 和 vendor.js 文件dist/assets也失败。
我也无法从dist本地机器的文件夹中运行独立的 ember 应用程序,同样的错误。
有没有人试过。如果是的话,如何正确地做到这一点?
我已经使用 ember-cli 成功创建了一个小型应用程序。我尝试将它推送到我的 github repo 的 gh-pages 分支,但它在浏览器控制台中显示错误
Uncaught ReferenceError: require is not defined
加载 vendor.js 和 vendor.js 文件dist/assets也失败。
我也无法从dist本地机器的文件夹中运行独立的 ember 应用程序,同样的错误。
有没有人试过。如果是的话,如何正确地做到这一点?
自 2014 年 12 月以来,还有一个用于此的 ember-cli 插件。
首先确保在 github 上设置modulePrefix了你的 repo 的名称。config/environment.js例如,对于https://github.com/username/my-cool-repo它应该是modulePrefix: 'my-cool-repo'.
然后按照以下说明进行操作:
安装插件。
$ ember install:addon ember-cli-github-pages
提交插件所做的更改。
$ git add . && git commit -m "Installed addon ember-cli-github-pages"
仅使用必要的文件创建gh-pages分支。
$ git checkout --orphan gh-pages && rm -rf `ls -a | grep -vE '.gitignore|.git|node_modules|bower_components|\.\/|\.\.\/'` && git add . && git commit -m "Initial gh-pages commit"
切换回您的源分支(很可能master)。
$ git checkout master
将您的 ember 应用程序构建到gh-pages分支。
$ ember gh-pages:commit --message "Initial gh-pages release"
将所有内容(或至少是gh-pages分支)推送到 github。
(这对于 ember-cli <= 0.1.4 有所不同,将来可能会再次更改。请务必访问插件的自述文件。)
正如评论已经说过的那样:将baseUrlin更改config/environment.js为您要将应用程序推送到的 GitHub 存储库的名称。例如:
您的 GitHub 存储库被调用myEmberApplication并位于
https://github.com/yourUsername/myEmberApplication.git
那么这个项目的 gh-pages 的 URL 将是
https://yourUsername.github.io/myEmberApplication
因此,在您的情况下,您必须将baseUrlfrom /(default) 更改为/myEmberApplication.
您必须这样做的原因是因为 ember-cli 会将<base>标头添加到您的index.html文件中。