Vue.js app works in development but not mounting template in production with Rails 5.2.0 / Webpacker - blank screen with no errors in console

后端 未结 2 358
余生分开走
余生分开走 2021-01-12 18:40

I\'m using Rails 5.2.0 and Webpacker gem to deploy a Vue application.

The show.html.erb file is very simple:

2条回答
  •  不思量自难忘°
    2021-01-12 19:13

    I had similar problem in Rails 5.2 + webpack Vue. All was good in development, but not working in production. After hours of investigating I found the reason. It was in this recommendation from webpaker gem docs.

    Adding this

    Rails.application.config.content_security_policy do |policy|
      if Rails.env.development?
        policy.script_src :self, :https, :unsafe_eval
      else
        policy.script_src :self, :https
      end
    end
    

    brokes production. Removing else part - fixing the situation.

    Chrome silently ignoring this. Firefox shows warnings.

提交回复
热议问题