How do I execute a post build hook in an ember-cli Brocfile.js?

試著忘記壹切 提交于 2019-12-10 13:14:11

问题


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).

How do I tell my Brocfile.js to copy the outputted index.html file after it is done building?

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.

I currently have a deply.sh script that does this but I wanted to know if there was a way using Broccoli for this?


回答1:


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)

Create your addon with ember g in-repo-addon <addon-name>

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');
    }
};

Example from Ghost

Ember-cli docs: developing addons and scaffolding in-repo addons



来源:https://stackoverflow.com/questions/28835255/how-do-i-execute-a-post-build-hook-in-an-ember-cli-brocfile-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!