Automatically precompile assets before pushing to

2019-03-13 21:29发布

Is it possible to automatically precompile my assets in a Rails app before pushing out to Heroku? I always forget to do it, so it would be nice if when I typed git push heroku master, it would first run rake assets:precompile ; git commit add . ; git commit -a -m "Precompile.", or something to that effect.

Has anyone achieved such a solution? Possibly without hooks? Though I suspect that is the only way.

5条回答
贪生不怕死
2楼-- · 2019-03-13 21:38

You could always alias heroku or something similar to rake assets:precompile ; git commit add . ; git commit -a -m "Precompile." ; git push heroku master in your bash profile ie

#in ~/.bash_profile 
alias precompile_push='rake assets:precompile ; git commit add . ; git commit -a -m "Precompile." ; git push heroku master'
查看更多
Explosion°爆炸
3楼-- · 2019-03-13 21:50

I finally figured this out. I was indeed on the Cedar stack. The problem was that I had checked my public directory into Git, and when I pushed to Heroku, it realized that public existed, and thus assumed I precompiled. Running git rm -r public and adding public/** to my .gitignore, then pushing, fixes the problem.

查看更多
够拽才男人
4楼-- · 2019-03-13 21:58

It sounds like you might not be on Heroku's Cedar Stack? If you're using the asset pipeline (Rails -v >= 3.1), cedar provides three options for compiling assets.

From the docs:

If you have not compiled assets locally, we will attempt to run the assets:precompile task during slug compilation.

查看更多
家丑人穷心不美
5楼-- · 2019-03-13 22:02

On the cedar stack, it will do this during slug compilation. I recommend that.

查看更多
太酷不给撩
6楼-- · 2019-03-13 22:03

I've created a gem that run as daemon and automatically pull changes from a Git repo, precompiles assets, commit and push back.

https://github.com/nectify/rails-precompile2git/

查看更多
登录 后发表回答