【问题标题】:How to run "grunt build" during Heroku deployment (angular and ruby-on-rails app)如何在 Heroku 部署期间运行“grunt build”(角度和 ruby​​-on-rails 应用程序)
【发布时间】:2014-01-22 14:54:36
【问题描述】:

我想在 Heroku 上部署一个 angular+rails 应用程序。该应用基于 Emmanual Oda's example code 构建,并使用 Grunt 编译其资产。

与其在本地编译我的资产然后将它们提交到 git,我更愿意在 Heroku 上编译它们。也就是说,我想在部署我的应用程序时自动在 Heroku 上运行 grunt build

有谁知道我可以如何配置 Heroku 来做到这一点?

编辑

我知道使用 Node.js 应用程序可以进行服务器端资产编译,例如使用 mbuchetics' fork of the heroku nodejs buildpack。但是,当我按照该站点上的说明推送到 Heroku 时,出现以下错误

-----> Fetching custom git buildpack... done

 !     Push rejected, no Cedar-supported app detected

编辑 2

目前我正在使用在本地运行 grunt build 的 Rake 任务进行部署。

task :deploy do
  system("rm -rf ./public/*")       # empty the public directory
  system("cd ngapp; grunt build")

  # make a bogus manifest file to turn off asset compilation on heroku 
  #   see here: https://devcenter.heroku.com/articles/rails-asset-pipeline
  system("mkdir public/assets; touch public/assets/manifest-098f6bcd4621d373cade4e832627b4f6.json")  

  system("git add public/")
  system("git commit -m \"deploying...\"")
  system("git push heroku master")
end

最好使用服务器端解决方案!

【问题讨论】:

标签: ruby-on-rails git angularjs heroku gruntjs


【解决方案1】:

我相信这就是你想要的:http://www.angularonrails.com/deploy-angular-rails-single-page-application-heroku/

此解决方案使用多个 buildpack 在生产环境中运行 grunt build。版本控制中没有构建工件。

【讨论】:

    【解决方案2】:

    我的项目也基于该示例 Rails 应用程序结构。我可以问一下为什么您希望 heroku 编译您的 grunt 构建而不是提交它吗?让 heroku 编译它意味着更长的部署时间。我所做的是我有一个部署脚本运行 grunt build 并在提交到构建分支之前运行所有测试。该构建分支被推送到heroku。这样,我的开发分支就可以保持干净,而无需在公共文件夹中编译资产。

    【讨论】:

    • 嗯。好的。拥有一个单独的构建分支是我没有想到的解决方案。尽管如此,在 Heroku 上编译资产似乎更优雅。我仍然很想知道这是否可能。不过感谢您的回答!
    猜你喜欢
    • 2018-06-10
    • 2016-01-06
    • 2021-03-18
    • 2016-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多