-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
publicPath should not include RAILS_RELATIVE_URL_ROOT #2140
Comments
What is the difference between |
I believe
|
Not in all cases. If I require a css file inside my module and said css file includes an image from it's package, that image doesn't properly load. It doesn't know anything about the relative url root. It becomes a broken asset. It works fine if the app isn't deployed in a sub directory. But for apps in sub directories, which is what we use relative url root for in the first place, it breaks. How is everyone else telling webpack that the app is deployed in a sub directory, so assets properly load? |
@rdavid369: I'm facing similar issues with image URLs inside CSS files being broken, since they don't have knowledge of I've been able to workaround this issue by essentially bringing back the changes in #1428, although I'm not totally certain if this is the correct solution. But it at least seems to be working for me so far. I've patched things by prepending this to the very beginning of const config = require('@rails/webpacker/package/config');
if (process.env.RAILS_RELATIVE_URL_ROOT) {
const path = require('path');
config.publicPath = path.join(process.env.WEBPACKER_ASSET_HOST || '/', process.env.RAILS_RELATIVE_URL_ROOT, `${config.public_output_path}/`);
config.publicPathWithoutCDN = path.join(process.env.RAILS_RELATIVE_URL_ROOT, `${config.public_output_path}/`);
} |
@GUI I will give this a try! Much appreciated! |
@GUI you saved my day ! Is there still no other way to make this working ? |
@GUI's solution worked for me as well. It seems like |
It's my understanding that all paths defined in rails server are relative to the
RAILS_RELATIVE_URL_ROOT
, and webpack publicPath should behave the same way. For example:RAILS_RELATIVE_URL_ROOT = /app
public_output_path = packs
(webpacker.yml)Working result would be
javascript_pack_tag
-><script src= '/app/packs/...'>
manifest.json
->/packs/...
publicPath
->/packs
However, under the current implementation,
javascript_pack_tag
-><script src= '/app/packs/...'>
manifest.json
->/packs/...
publicPath
->/app/packs
which will not be found because rails assumes routes relative to
RAILS_RELATIVE_URL_ROOT
.See: #1357 and comments. Essentially I'm proposing that the merged code that addresses that issue should be reverted. Maybe something changed since then or maybe I'm missing something.
The text was updated successfully, but these errors were encountered: