Joh*_*hir 9 ruby ruby-on-rails heroku asset-pipeline
我在lib/tasks/foo.rake中有这个:
Rake::Task["assets:precompile"].enhance do
print ">>>>>>>> hello from precompile"
end
Rake::Task["assets:precompile:nondigest"].enhance do
print ">>>>>>>> hello from precompile:nondigest"
end
Run Code Online (Sandbox Code Playgroud)
当我在rake assets:precompile本地运行时,两个消息都被打印出来.
当我推送到heroku时,只打印非自动消息.但是,根据buildpack,push正在执行与本地完全相同的命令.
为什么基础资产的增强:预编译案例在heroku上不起作用但在本地工作?
我一直在寻找到这个问题,我发现的行为assets:precompile 取决于如果RAILS_ENV和RAILS_GROUPS都设置或不看看这个地方.
# This works
? bundle exec rake assets:precompile RAILS_ENV=production
>>>>>>>> hello from precompile:nondigest
>>>>>>>> hello from precompile
# This works
? bundle exec rake assets:precompile RAILS_GROUPS=assets
>>>>>>>> hello from precompile:nondigest
>>>>>>>> hello from precompile
?
# This does not work :'(
? bundle exec rake assets:precompile RAILS_ENV=production RAILS_GROUPS=assets
>>>>>>>> hello from precompile:nondigest
?
Run Code Online (Sandbox Code Playgroud)
问题来自https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/sprockets/assets.rake in invoke_or_reboot_rake_taskmethod如果你更换Rake::Task[task].invoke线路ruby_rake_task task然后它就像你期望的那样工作.我一直在探究为什么会这样,并且没有找到原因.
由于两个变量都是在Heroku构建包中设置的,因此您可以在不设置GROUP和ENV设置的情况下创建自定义构建包,但我认为这样做太过分了.在这种情况下,您应该能够增强assets:precompile:primary或assets:precompile:all实现与您期望的意图类似的结果.
| 归档时间: |
|
| 查看次数: |
938 次 |
| 最近记录: |