-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Images in css files do not get assetsPrefix in production build #37654
Comments
Are you using I am getting prefix when I use this toggle. There was regression some time ago, but it was fixed in |
Yes, I do "gatsby build --prefix-paths" when build for prod. I get assets prefix for all css, js , images included directly to html files, but all background images added to css files directly are not getting assets prefix. |
Ok, after some changes I manage to reproduce - this only happens when image / url path starts with This seems to be because of this config gatsby/packages/gatsby/src/utils/webpack-utils.ts Lines 313 to 321 in 66584a2
--edit: |
Thank you for checking! When I add static background images to css files with relative path starting with ../ ... in prod version I get assetsPath added, as well as caching name, thanks. But all svg images are inlined in css files as something like Sorry, this is not a bug, since everything works with a relative path. All static images that are being added via js files as relative or absolute paths (not as an import) , for example, as The same static image is being treated differently if added via css or via js: different path in public folder, in one case it gets caching names, in other no. I kind of understand why it's happening but it leads to an issue when static files being added to public folder into multiple places. In my case the same static image |
Not a bug |
Preliminary Checks
Description
When add static background images to css files, Gatsby 5 doesn't add assetPrefix (added to gatsby-config.js) to them in production build. It makes it impossible to use cdn, because not all images can be added to js files as img HTML tag or imported to components where assetPrefix is being applied correctly (with withPrefix function).
Reproduction Link
https://codesandbox.io/s/wandering-rgb-hx2pp4
Steps to Reproduce
Create a css file
.container { background-image: url("/logo.svg") }
Add container class name to html
Add to gatsby-config.js:
assetPrefix: https://cdn.example.com
Build the app for production, see pages source code , inlined styles do not have assetsPrefix added to image paths.
Expected Result
In prod output inlined css styles should look like
<style>.container{backgrround-image:url('https://cdn.example.com/logo.svg')}</style>Actual Result
<style>.container{backgrround-image:url('/logo.svg')}</style>Environment
Config Flags
No response
The text was updated successfully, but these errors were encountered: