rake assets:precompile taking extremely long to complete

后端 未结 4 1222
情深已故
情深已故 2020-12-15 23:02

In my dev sandbox

RAILS_ENV=production rake assets:precompile

is taking over 4 minutes to complete. Is this normal. On heroku it is taking

4条回答
  •  离开以前
    2020-12-15 23:36

    The best option is compile locally, commit and deploy as normal, disabling the precompile task for production. I am doing this for all my production apps now.

    To get around those compiled assets being served in Development mode (overriding dynamic pipeline compilation, which you need) do the following.

    In development.rb place the following line:

    config.assets.prefix = "/dev-assets"
    

    This over-rides whatever is set in application.rb (normally "/assets").

    You will also need this in application.rb:

    config.assets.initialize_on_precompile = false
    

    That stops the task trying to connect to your database. (Beware if you are referring to ActiveRecord models in your assets, as this won't work).

    These changes allow you to compile and commit the assets to your repository locally, and have those files in your working development tree, but for development requests to still be sent to Sprockets. Plus, you only have to precompile and commit when something has actually changed.

    Ref my blog post

提交回复
热议问题