-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Closed
Labels
topic: mediaRelated to gatsby-plugin-image, or general image/media processing topicsRelated to gatsby-plugin-image, or general image/media processing topicstopic: webpack/babelWebpack or babelWebpack or babeltype: bugAn issue or pull request relating to a bug in GatsbyAn issue or pull request relating to a bug in Gatsby
Description
Preliminary Checks
- This issue is not a duplicate. Before opening a new issue, please search existing issues: https://github.com/gatsbyjs/gatsby/issues
- This issue is not a question, feature request, RFC, or anything other than a bug report directly related to Gatsby. Please post those things in GitHub Discussions: https://github.com/gatsbyjs/gatsby/discussions
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
System:
OS: macOS 13.1
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v18.12.1/bin/yarn
npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
Browsers:
Chrome: 109.0.5414.119
Firefox: 108.0.2
Safari: 16.2
npmPackages:
gatsby: ^5.6.0 => 5.6.0
gatsby-link: ^5.6.0 => 5.6.0
gatsby-page-utils: ^3.6.0 => 3.6.0
gatsby-plugin-canonical-urls: ^5.6.0 => 5.6.0
gatsby-plugin-env-variables: ^2.3.0 => 2.3.0
gatsby-plugin-eslint: ^4.0.3 => 4.0.3
gatsby-plugin-manifest: ^5.6.0 => 5.6.0
gatsby-plugin-preconnect: ^1.4.0 => 1.4.0
gatsby-plugin-purgecss: ^6.2.1 => 6.2.1
gatsby-plugin-root-import: ^2.0.9 => 2.0.9
gatsby-plugin-sass: ^6.4.0 => 6.6.0
gatsby-plugin-sitemap: ^6.4.0 => 6.6.0
gatsby-plugin-split-css: ^2.0.3 => 2.0.3
gatsby-plugin-styled-components: ^6.4.0 => 6.6.0
gatsby-source-filesystem: ^5.6.0 => 5.6.0
npmGlobalPackages:
gatsby-cli: 5.6.0Config Flags
No response
Metadata
Metadata
Assignees
Labels
topic: mediaRelated to gatsby-plugin-image, or general image/media processing topicsRelated to gatsby-plugin-image, or general image/media processing topicstopic: webpack/babelWebpack or babelWebpack or babeltype: bugAn issue or pull request relating to a bug in GatsbyAn issue or pull request relating to a bug in Gatsby