如何在ember-cli Brocfile.js中执行post build hook? [英] How do I execute a post build hook in an ember-cli Brocfile.js?
问题描述
我有一个ember-cli项目构建到 dist /
目录。我已经配置了应用程序来处理 dist /
目录中的资产,并将历史记录设置为使用哈希而不是pushState。这允许我将 index.html
链接到根目录。推理是将项目推送到GitHub上的 gh-pages
需要根 index.html
,而ember应用程序需要路由绝对不是亲戚(AFAIK)。但是,GitHub不会遵循sym链接,需要输出 index.html
的副本。这有效,现在我有2个构建步骤( ember build
和 cp dist / index.html ./index.html
)
I have a ember-cli project that builds to the dist/
directory. I've configured the app to handle assets in the dist/
directory and set the history to use a hash instead of pushState. This allows me to sym-link the index.html
to the root. The reasoning is that pushing the project to gh-pages
on GitHub requires a root index.html
and ember apps require routing to be absolute not relative (AFAIK). GitHub however will not follow sym-links and require a copy of the output index.html
. This works and now I have 2 build steps (ember build
and cp dist/index.html ./index.html
).
如何告诉我的 Brocfile.js
来复制输出的索引。 html
文件完成建立后
How do I tell my Brocfile.js
to copy the outputted index.html
file after it is done building?
有一点回溯历史:我正在开发一个ember-cli插件。我在GitHub上托管它。我需要提供一个演示网站。 gh-pages
是托管演示网站的正确场所。所以我在 gh-pages
分支中创建一个ember-cli应用程序。我不能将输出文件夹设置为 ./
,因为ember构建将 rm -rf
破坏源的输出目录。所以它必须是 dist /
。我不能使用< meta http-equiv =刷新...
,因为Ember在启动时引发了路径和崩溃。所以我的解决方案是将 index.html
链接/复制到更高级别,并更改ember的配置,以添加 dist /
目录到资产,并将路由设置为哈希而不是pushState。
A bit of back-history: I am developing an ember-cli addon. I'm hosting it on GitHub. I need to provide a demo site. gh-pages
is the correct place to host the demo site. So I create an ember-cli app in the gh-pages
branch. I could not set the output folder to ./
because the ember build will rm -rf
the output directory destroying the source. So it has to be dist/
. I couldn't use a <meta http-equiv="Refresh"...
because Ember borked up the paths and crashes on start. So the solution I had was to sym-link/copy the index.html
to a higher level and change ember's config to prepend the dist/
directory to assets and set the routing to hash instead of pushState.
我目前有一个 deply.sh
脚本这样做,但是我想知道是否有一种使用Broccoli的方法?
I currently have a deply.sh
script that does this but I wanted to know if there was a way using Broccoli for this?
推荐答案
结束于 Ghost 。使用ember-cli为你自己生成一个内置的插件,然后使用你最喜爱的库来复制文件(我已经有fs-extra和我使用它了)
We this for over at Ghost. Use ember-cli to generate an in-repo-addon for yourself, and then use your favorite library for copying the file (I already had fs-extra and am using it)
在中创建您的插件ember g in-repo-addon< addon-name>
in code> /lib/<addon-name>/index.js :
in /lib/<addon-name>/index.js
:
module.exports = {
name: '<addon-name>',
postBuild: function (results) {
var fs = this.project.require('fs-extra');
fs.copySync(results.directory + '/index.html', '../server/views/default.hbs');
}
};
Ember-cli docs:开发插件和脚手架in-repo插件
Ember-cli docs: developing addons and scaffolding in-repo addons
这篇关于如何在ember-cli Brocfile.js中执行post build hook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!