Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share asset_host from rails with webpack #208

Closed
schovi opened this issue Mar 30, 2017 · 1 comment
Closed

Share asset_host from rails with webpack #208

schovi opened this issue Mar 30, 2017 · 1 comment
Labels

Comments

@schovi
Copy link

schovi commented Mar 30, 2017

Today I reach issue, where some of my assets was loaded from same domain as app and not from CDN as i have configured in environment/production.rb

(my solution)

if ENV['ASSETS_HOST'].present?
  config.action_controller.asset_host = ENV['ASSETS_HOST']
end

webpack scripts and styles was handled fine, because url is generated in rails, but all assets loaded inside .jsx? or .css did not have this domain obviously. It took me some time to find where is root cause of this and then solution was easy.

config/webpack/configuration.js

from

const publicPath = env.NODE_ENV !== 'production' && devServer.enabled ?
  `http://${devServer.host}:${devServer.port}/` : `/${paths.entry}/`

to

let publicPath
if (env.NODE_ENV !== 'production' && devServer.enabled) {
  publicPath = `http://${devServer.host}:${devServer.port}/`
} else {
  publicPath = `${env.ASSETS_HOST}/${paths.entry}/`
}

My opinion is, it should be shared across whole environment by default, because it can cause lot of confusion, but on other hand I can't find solution, which can be done without changing something directly in rails gem.

@gauravtiwari
Copy link
Member

Fixed by #224

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants