[BUG] in styled jsx loaders not apply to images
See original GitHub issuei have files
/pages/_App.js
/res/images/image.jpg
export default function App() {
// language=Stylus
return <style jsx global>{ `
body {
background-image: url("../res/images/image.jpg");
}
` }</style>
}
Problem
url("../res/images/image.jpg") will not replace to /_next/static/images/lol-c8bbed083d312e8f1cccb6069d6f7919.png. styled jsx not applied webpack loaders, and not create optimized next.js assets
Temporary solution
export default function App() {
// language=Stylus
return <style jsx global>{ `
body {
background-image: url(${ require("../res/images/image.jpg") });
}
` }</style>
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
[BUG] in styled jsx loaders not apply to images #12158 - GitHub
i have files /pages/_App.js /res/images/image.jpg export default function App() ... [BUG] in styled jsx loaders not apply to images #12158.
Read more >React.js styled-components importing images and using them ...
You should import images in the following manner (assuming that you have webpack configured for importing media assets).
Read more >css-loader | webpack - JS.ORG
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >styled-jsx - npm
Full CSS support for JSX without compromises. Latest version: 5.1.1, ... Start using styled-jsx in your project by running `npm i styled-jsx`.
Read more >Next.js image optimization techniques | Uploadcare Blog
UPD: Uploadcare now has a Next.js Image Loader and Component. ... it's possible to import an image as a React component or from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

temporary solution:
@jamesmosier @timneutkens
if i use webepack base 64 loader, for svg icons, then render component with jsx styles generate 10kb+ style text? every render iteration? if i use 10 png icons by 10kb, i create 100kb style text by every render?
next js cool framework, and your recommendations are wonderful =)
the images in this folder are source, and do not go through webpack processing and are not suitable for production. hashes are not added to their names, they are not stuck together into single sprites, etc. These are raw files not processed by webpack. such files are called sources.
it is unacceptable to use raw files directly; all assets must always be imported through the webpack system.