SCSS absolute image urls are not transformed
See original GitHub issueI’m really having a hard time making this plugin work with my SASS files, so to make sure it’s not my own complex configuration that is in the way, I created a new project from scratch just to test the plugin and try and make it work with CSS url
.
The simple project
// pages/styles.scss
.test {
background-image: url('/static/test.jpg'); // this is not transformed
}
// pages/index.js
import React from 'react';
import './styles.scss';
export default () => <div className="test">Welcome to next.js!</div>
// next.config.js
const withSass = require('@zeit/next-sass');
const withOptimizedImages = require('next-optimized-images');
module.exports = withOptimizedImages(withSass({
assetPrefix: 'http://localhost:3000/',
}));
And the package.json
{
"dependencies": {
"@zeit/next-sass": "^1.0.1",
"next": "^8.0.0",
"next-optimized-images": "^2.3.3",
"node-sass": "^4.11.0",
"react": "^16.8.1",
"react-dom": "^16.8.1"
},
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
}
}
Note that our other project is on Next v7 (if that changes anything).
Expected behaviour
Since I’m using the assetPrefix
Next config option, I’m hoping to see my image URL within the compiled CSS to change to something like this: http://localhost:3000/_next/static/test-hashHere.jpg
.
Current behaviour
It’s not changing at all. I’m seeing the image since the assetPrefix is the same as my default dev server and Next is correctly parsing the image since if I change the path, it fails to compile.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Can't use relative paths in url() in scss files #12797 - GitHub
I would like to be able to use the relative file path in the scss file. I know this is solved by using...
Read more >url() does not refer to correct file when using relative paths in ...
Considering a CSS import resolves the URL files relative to the file they are found in and SCSS does not adjust the URL...
Read more >url() - CSS: Cascading Style Sheets - MDN Web Docs
The url() CSS function is used to include a file. The parameter is an absolute URL, a relative URL, a blob URL, or...
Read more >'Combine CSS Files' breaking image URLs - WordPress.org
1. When we combine the CSS, we check for full URLs and if we find such, we leave them as is. 2. When...
Read more >Absolute / domain-relative path for asset URLs in CSS - bud
However, the asset url(...) s inside the CSS are still relative to their stylesheet (e.g. url(images/water-sand.9a11c3.jpg) . This is completely valid and works ......
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 FreeTop 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
Top GitHub Comments
To make it work with absolute paths using aliases in our SCSS, I needed to add the aliases configuration to the webpack configuration, something like that:
So it would work like this in our SCSS:
In my example above, I mainly changed my
styles.scss
to: