Ahh.... After a long hours of debugging I have finally found the issue. It was my foolishness because of which I struggled. I wanted to delete this question but thought that it would help new comers like me when the stuck to similar issues.

Problem was here

loader: 'url-loader?limit=10000'

I was setting the limit to file size of 10kb without really knowing what it does. And the image which I was loading was of size 21kb ! This happens when you copy some else webpack config files :) Sign of javascript fatigue !

Answer from WitVault on Stack Overflow
🌐
Htmlcsstoimage
htmlcsstoimage.com
HTML/CSS to Image API - Automate your image generation
Convert HTML to an image (jpg, png, webp). Renders images exactly like Google Chrome. Works with PHP, JavaScript, Ruby, .NET and more.
Pricing
Convert HTML to an image (jpg, png, webp). Renders images exactly like Google Chrome. Works with PHP, JavaScript, Ruby, .NET and more.
Examples
Quick start samples to help you generate images using automation.
🌐
HUGO
discourse.gohugo.io › support
Setting images as background-image in css/sass - support - HUGO
February 13, 2024 - Hi, just looking for some clarification. I am trying to set a background image using sass. I initially placed the images in /assets/images/image.png. I then called the image in my sass using background-image: url("/images/image.png"). It worked. I did it this way as I read somewhere online ...
🌐
GeeksforGeeks
geeksforgeeks.org › css › sass-variable-for-images-path
SASS variable for images path - GeeksforGeeks
June 27, 2020 - body { margin: 0 auto; background: url(/assets/images/gfg.gif); width: 100%; } We can also use multiple variables in a single path to an image.
🌐
GitHub
github.com › sass › sass › issues › 1015
SASS @import and maintaining URLs for images etc · Issue #1015 · sass/sass
October 8, 2013 - Shouldn't URLs be maintained when importing .scss files from other directories? e.g. File structure: css/ main.scss dir/ dir.scss main.scss: @import './dir/dir.scss'; dir.scss: body { background: url('../../arbitrary/bg.jpg'); } Generate...
Author   denniszhao
🌐
HTML/CSS to Image
docs.htmlcsstoimage.com
HTML/CSS to Image API | HTML/CSS to Image
Convert HTML to an image (jpg, png, webp). Renders images exactly like Google Chrome. Works with PHP, JavaScript, Ruby, .NET and more.
Find elsewhere
🌐
Roots Discourse
discourse.roots.io › sage
Loading image in SCSS - sage - Roots Discourse
March 19, 2019 - Hi, I have problem with image loading. I tried everything from previous topics but nothing work. .hero-image { background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("‥/images/hero.jpg"); } also I tried ‥/dist/images/hero.jpg or ‥/resources/assets/images/hero.jpg and ‥/images/hero.jpg I used WAMPP server, localhost, my config.json { “entry”: { “main”: [ “./scripts/main.js”, “./styles/main.scss” ], “customizer”: [ “./scripts/customizer.js” ] }, “publ...
Top answer
1 of 3
35

depending on how your packs are structured/applied you might be able to use a loop to generate a bunch of generic styles. See the documentation here: http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#id35

Do you really need 3 separate components to get your image url? wouldn't: $img and then setting that to /folder/img.ext be far easier?

Also, you don't need the #{} for repeat by the way.

I hope this is what you're after… the question is not very specific in terms of what you need the outcome to actually be.

Cheers, Jannis

Update:

Okay, I see you've updated your question (thanks for that). I believe this could be a little better for general use:

@mixin background($imgpath,$position:0 0,$repeat: no-repeat) {
    background: {
        image: url($imgpath);
        position: $position;
        repeat: $repeat;
    }
}
.testing {
    @include background('/my/img/path.png');
}

This will then output:

.testing {
  background-image: url("/my/img/path.png");
  background-position: 0 0;
  background-repeat: no-repeat;
}

Or you can use the shorthand version:

@mixin backgroundShorthand($imgpath,$position:0 0,$repeat: no-repeat) {
    background: transparent url(#{$imgpath}) $repeat $position;
}
.testing2 {
    @include backgroundShorthand('/my/img/path.png');
}

Which will generate:

.testing2 {
  background: transparent url(/my/img/path.png) no-repeat 0 0;
}

Lastly if you want to specify your base path to your image directory separately you can do the following:

$imagedir:'/static/images/'; // define the base path before the mixin

@mixin backgroundShorthandWithExternalVar($filename,$position:0 0,$repeat: no-repeat) {
    background: transparent url(#{$imagedir}#{$filename}) $repeat $position;
}
.testing3 {
    @include backgroundShorthandWithExternalVar('filename.png');
}

This will then generate:

.testing3 {
  background: transparent url(/static/images/filename.png) no-repeat 0 0;
}

Is this what you needed?

If not feel free to update the question or reply/comment.

2 of 3
4

some other sample:

path to the image:

$path--rel      : "../images";

color

$black: #000000;

creating the mixin:

@mixin background-image($img, $background-position, $background-color) {
    background-image: url('#{$path--rel}/#{$img}');
    background-repeat: no-repeat;
    background-position: $background-position;
    background-color: $background-color ;
} 

using the mixing:

.navbar-inverse {
  @include background-image("header.png", right, $black); 
}

result:

.navbar-inverse {
  background-image: url("../images/header.png");
  background-repeat: no-repeat;
  background-position: right;
  background-color: #000000;
}
🌐
GitHub
github.com › lexich › css-image
GitHub - lexich/css-image: generator css and scss templates for images
var imagecss = require("css-image"); var files = [{ width: 400, height: 300, file: "t.png" }]; var result = imagecss(files ,{ css: true, scss: true, retina: true, squeeze: 2, root: "root" })
Starred by 4 users
Forked by 5 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
Caffeine Creations
caffeinecreations.ca › home page › sass variable for image path
SASS Variable for Image Path | Caffeine Creations
February 28, 2019 - Copy to clipboard Error: Invalid CSS after \"...path/hero-image\": expected \")\", was \".jpg) no-repeat...\
Price   $
Call   647-799-6330
Address   Toronto, Canada
🌐
Stack Overflow
stackoverflow.com › questions › 50550384 › handle-image-in-scss-with-webpack
Handle Image in SCSS with Webpack - Stack Overflow
Connect and share knowledge within a single location that is structured and easy to search. Learn more about Teams · Get early access and see previews of new features. Learn more about Labs ... module: { rules: [ { test: /\.js$/, use: { loader: "babel-loader", options: { presets: ['babel-preset-env'] } } }, { test: /\.scss$/, use: [ MiniCssExtractPlugin.loader, "css-loader", "sass-loader" ] }, { test: /\.(jp(e)?g|png|gif|svg)$/, use: { loader: 'url-loader', options: { limit: 8192, name: 'css/images/[name].[ext]' } } } ]
🌐
RenderForm
renderform.io › convert-html-to-image
HTML/CSS/JS to Image | RenderForm
Convert any HTML with CSS and JavaScript to image with RenderForm API. Easy setup. No coding required.
🌐
Stack Overflow
stackoverflow.com › questions › 75629908 › scss-file-use-of-image-url-wont-appear-in-page-styles
sass - SCSS file use of image / url() won't appear in page styles - Stack Overflow
For this specific issue, the file path to the image may be correct according to the location of your variables.scss, but don't forget that ultimately the page runs off of the converted main.css file, so you must adjust your path to be correct from the main.css location.
🌐
Ibexa
doc.ibexa.co › projects › connect › en › latest › apps › html-css-to-image
HTML/CSS to Image - Ibexa Connect Documentation
The HTML/CSS to Image modules enable you to convert HTML/CSS to an image in your HTML/CSS to Image account.
🌐
freeCodeCamp
forum.freecodecamp.org › t › setting-background-image-in-react-using-scss-webpack › 159995
Setting background image in React using SCSS / Webpack - The freeCodeCamp Forum
October 8, 2017 - I’m having trouble setting a background image for a react app, using SCSS. My app has the following structure, with most files removed for readability: --node_modules --public ----index.html ----bg-img.jpg --src ----components ----styles ------base --------_base.scss --------_settings.scss ------components ------styles.scss ----app.js I’m trying to reference the bg-img.jpg in the public folder with background-image: url('bg-img') in the _base.scss file.
🌐
Reddit
reddit.com › r/webdev › background-image: url() using gatsby and sass does not work
r/webdev on Reddit: background-image: url() using Gatsby and SASS does not work
September 13, 2020 -

Hello there,

Not sure if this is a Gatsby related issue or a SASS issue. But whenever I'm trying to set the background image of and element (div) with the background-image: url() css property in SASS I get the following error:

./src/styles/main.scss (./node_modules/css-loader??ref--14-oneOf-1-1!./node_modules/postcss-loader/src??postcss-3!./node_modules/sass-loader/dist/cjs.js??ref--14-oneOf-1-3!./src/styles/main.scss)
Module not found: Error: Can't resolve '../../../images/home/blog-bg.png' in '/Users/aeum3893/Documents/work/folder/tech/src/styles'

It can't find the image with the provided path and I have tried different paths like:

- Full path with quotes & without quotes:

background-image: url('/Users/aeum3893/Documents/work/folder/tech/src/images/home/blog-bg.png');

- Relative Path with quotes & without quotes:

background-image: url('src/images/home/blog-bg.png');

- Funky stuff with quotes and without:

background-image: url(../../../images/home/blog-bg.png);

background-image: url(/../../../images/home/blog-bg.png);
background-image: url(blog-bg.png);

And so on... It breaks. I don't know what I'm missing here.

Folder structure:
- src

-- components

-- images // Images that I want to use

-- pages // Pages

-- shared // Reusable components

-- styles // SASS folder