Webpacker: Pack assets ignores Rails assets prefix

Created on 12 Jun 2018  路  3Comments  路  Source: rails/webpacker

Configuration

In my Rails app we change the asset prefix and we use a asset host to a static location.
Because multiple rails apps use the same static host we prefix them like this in the initializer:

Rails.application.config.assets.prefix = "/assets/#{Rails.application.class.parent}"
Rails.application.config.assets.manifest = "public#{Rails.application.config.assets.prefix}/sprockets-manifest.json"

Details

This works well for normal rails assets directory. Now we added webpacker to the project and in the webpacker.yml you can't use ERB code like in other yml config files and there is no information available to reconfigure the public_output_path dynamically with initializer config.

I thought ok then it doesn't use the Rails asset configuration so I let the app serve it for now directly from the public dir with ENV['RAILS_SERVE_STATIC_FILES'] enabled. The app runs on domain: app.domain.com and the Rails asset host is set to assets.domain.com. Now I get the url in the html with: https://assets.domain.com/packs/application-a2e1bc1d0db09c347bf4.js. It should use the app.domain.com or use the prefix.

So expected behavior:

  1. Ignore the asset host set by rails and serve it on: https://app.domain.com/packs/application-a2e1bc1d0db09c347bf4.js
  2. Use the prefix assets path https://assets.domain.com/RailsAppName/packs/application-a2e1bc1d0db09c347bf4.js

Questions

  1. Why does the production compiled application does not use the asset prefix but it uses the asset host?
  2. Why can't we reconfigure the config?

Most helpful comment

U can try change output.publicPath in production webpack config (config/webpack/production.js) like:

process.env.NODE_ENV = process.env.NODE_ENV || 'production'

const environment = require('./environment')

environment.config.set('output.publicPath', '/prefix/')

module.exports = environment.toWebpackConfig()

All 3 comments

U can try change output.publicPath in production webpack config (config/webpack/production.js) like:

process.env.NODE_ENV = process.env.NODE_ENV || 'production'

const environment = require('./environment')

environment.config.set('output.publicPath', '/prefix/')

module.exports = environment.toWebpackConfig()

This is still a thing :(

@h0jeZvgoxFepBQ2C You can use this master branch: https://github.com/LeftClickBV/swaggard

It contains PR: #49 and #50

Was this page helpful?
0 / 5 - 0 ratings