如何在Heroku部署期间运行“grunt build”(angular and ruby​​-on-rails应用程序)

时间:2021-08-27 23:12:03

I'd like to deploy an angular+rails app on Heroku. The app is built off Emmanual Oda's example code, and compiles its assets using Grunt.

我想在Heroku上部署一个angular + rails应用程序。该应用程序是基于Emmanual Oda的示例代码构建的,并使用Grunt编译其资产。

Instead of compiling my assets locally and then committing them to git, I'd prefer to compile them on Heroku. That is, I'd like to run grunt build on Heroku automatically whenever my app is deployed.

我没有在本地编译我的资产然后将它们提交给git,我宁愿在Heroku上编译它们。也就是说,每当我的应用程序部署时,我都想自动在Heroku上运行grunt build。

Does anyone know how I can configure Heroku to do this?

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

EDIT

I know server side asset compilation is possible with Node.js apps, for example using mbuchetics' fork of the heroku nodejs buildpack. When I follow the instructions at that site and push to Heroku, though, I get the following error

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

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

 !     Push rejected, no Cedar-supported app detected

EDIT 2

For the time being I'm deploying using a Rake task that runs grunt build locally.

暂时我正在使用在本地运行grunt构建的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

A server side solution would be preferable!

服务器端解决方案更可取!

2 个解决方案

#1


6  

I believe this is what you want: http://www.angularonrails.com/deploy-angular-rails-single-page-application-heroku/

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

This solution uses multi buildpacks to run grunt build in production. No build artifacts in version control.

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

#2


2  

My project is also based off of that sample rails app structure. May I ask why you want heroku to compile your grunt build rather than committing it? Having heroku compile it means even longer deploy times. What I do is I have a deploy script run grunt build and also run all the tests before committing to a build branch. That build branch is pushed to heroku. That way my development branch stays clean without the compiled assets in the public folder.

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

#1


6  

I believe this is what you want: http://www.angularonrails.com/deploy-angular-rails-single-page-application-heroku/

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

This solution uses multi buildpacks to run grunt build in production. No build artifacts in version control.

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

#2


2  

My project is also based off of that sample rails app structure. May I ask why you want heroku to compile your grunt build rather than committing it? Having heroku compile it means even longer deploy times. What I do is I have a deploy script run grunt build and also run all the tests before committing to a build branch. That build branch is pushed to heroku. That way my development branch stays clean without the compiled assets in the public folder.

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