How to avoid precompiled assets being served in development mode?

前端 未结 4 1237
情书的邮戳
情书的邮戳 2020-12-07 13:58

I prefer not to concatenate JavaScript files in development mode, but serve them as individual files. So I configured:

development.rb:

confi         


        
相关标签:
4条回答
  • 2020-12-07 14:18

    In config/environments/development.rb set:

    config.assets.prefix = "/assets_dev"
    

    so that in development mode Rails will look there (but it will not find anything, as you will not compile assets in development (this is indeed what you are trying to do -- not compile assets)).

    When precompiling for production, use

    RAILS_ENV=production rake assets:precompile
    

    so it compiles into the default assets folder, public/assets.

    0 讨论(0)
  • 2020-12-07 14:20

    I tried this and it worked. rake assets:precompile RAILS_ENV=production

    I observed that the new version of assets pipeline does this when you run rake assets:precompile does rake assets:precompile:all

    0 讨论(0)
  • 2020-12-07 14:33

    in config/environments/development.rb set:

    config.serve_static_assets = false
    

    and no files from /public will be served

    0 讨论(0)
  • 2020-12-07 14:38

    It sounds like you are precompiling locally. Because the files exist in the expected location they are being served by your dev server, and the requests are not going to Sprockets.

    The only way to stop this is delete the compiled files.

    Normally you do not need to compile locally. It is expected that in almost all cases the precompile task will be run during deployment of the app. There is a Capistrano recipe for this on the asset pipeline guide page.

    If you do need to have those files locally committed to your repo you could use a branch to avoid the problem. Reserve your master branch for production code, and make a second branch for dev. Only compile and commit assets on master. When you switch to dev, they will be gone. Merge dev into master as required.

    Edit: Make sure you force your browser to update (control + F5) or you may find the old assets used from the browser cache!

    0 讨论(0)
提交回复
热议问题