The background image went missing after the webpack build due to the absence of the id svg-path.svg

I am currently using Next.js.

My styles look like this:

.img {
    background-image: url(path/to/my/svg/file.svg#icon);
}

However, when I run npm run dev, the styles for my element with the class name "img" change to:

.img {
    background-image: url(path/to/my/svg/file.jsbf730sh.svg);
}

I have lost the #icon id in the process.

I suspect that this issue is caused by the scss compiler, but I have been unable to find a solution.

Answer №1

For SVG files in Webpack, make sure to utilize the generator.filename along with the [fragment] replacement within the module rule:

module: {
  rules: [
    {
      test: /\.(png|jpe?g|ico|svg)$/,
      type: 'asset/resource',
      generator: {
        // Incorporate '[fragment]' in the output filename, e.g. icons.svg#home
        filename: 'img/[name].[hash:8][ext][fragment][query]',
      },
    },
  ],
},

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Placing an image in context with the background image

Looking for guidance on CSS styling. I have successfully set up a responsive background image on my page and now want to add a circular logo positioned at the bottom center of it. However, I am facing an issue where the logo's position changes when th ...

Implementing NextJS server-side rendering and static site generation after a user signs in or while making updates to

Having some experience with ReactJS, I am now delving into NextJS. A burning question keeps resurfacing in my mind about SSR/SSG. In the context of an e-commerce application where all pages (/products, /product, etc.) are either SSGed or SSRed, what happen ...

Increased height of iPad screen in landscape mode with no body content displayed (iOS7)

The issue: An unusual problem occurs when the specified URL is loaded on an iOS7 iPad in landscape mode; a vertical scrollbar appears. There is absolutely no content within the body, and it seems to be adjusting the body/html margin/padding. It should be ...

Adjusting Image Size based on Window Width for Internet Explorer

Based on the provided code snippet <style> .x{ background: url('img.jpg') no-repeat; background-size: contain; height: 100%; } </style> <div class="x"></div> It is functioning correctly in Chrome and Firef ...

What is the process for creating Bootstrap styles with Sass?

After obtaining the npm bootstrap package, I navigated to node_modules/bootstrap/dist/css/bootstrap.css and inspected the styles for .alert-danger: .alert-danger { color: #721c24; background-color: #f8d7da; border-color: #f5c6cb; } Despite searching ...

Place 4 divs within 2 divs, with one aligned to the left and the other to the right

I'm currently working on a small project using Angular 2 for an experiment, where I need to place 4 divs, each containing an image, within 2 divs. However, all the divs (with images) are stacked vertically instead of being placed next to each other, ...

Custom configuration for loading static images using Webpack file loader

Hello, I have a folder named /images which has a sub-directory called /static containing various images. I am wondering how I can configure webpack to make these images from the images/static path publicly available at dist/images/image-name.png, while k ...

Are the site-wide navigation links working on one page but not the other?

Currently, I am in the process of constructing a website on rails and have successfully integrated a site-wide navigation bar to display on all pages. However, an issue has arisen where the navbar is visible on both pages, yet the links and hover effects a ...

How can I display random images in the gallery?

I am looking for a gallery that is similar to the one in this provided link: The codes seem too complex for me to figure out on my own. Thank you ...

AngularStrap offers a dynamic and responsive navbar collapsing animation feature that enhances user

I am attempting to replicate the collapsible Bootstrap responsive navbar using AngularStrap. Check out this plunker: <div class="navbar navbar-inverse"> <div class="container" bs-collapse start-collapsed="true"> <div class="navbar- ...

Using HTML classes to align text with colored letters in the center

I'm attempting to alter the colors of individual letters within a sentence using html and css. After conducting some research, I came across this method: Here is the html and css code snippet I used: .green { font-size: 20px; color: #0F3; te ...

Issue on my website specifically occurring on Google Chrome and mobile devices

Hello, I seem to be having a CSS issue. Interestingly, my menu (burger menu) works perfectly fine on Firefox but is not functioning properly on Chrome and mobile devices. When I click the button, the menu doesn't open. Has anyone encountered a simil ...

Align an image with text using CSS and HTML

I'm having trouble with my CSS and HTML code. I want to align the text to the right of an image in a grid format, but it keeps appearing below the image instead. Here is the code snippet: <html> <head> <style type="text/css"> #conta ...

Guidelines for aligning input buttons at the center of an HTML form

My form contains multiple input buttons, however, the inputs are not centered on the page. Currently, they are displayed in a single row within the div. I would like them to fill the page width with a 20px margin on each side and adjust to the browser scre ...

Refresh a function following modifications to an array (such as exchanging values)

Looking to re-render a function after swapping array values, but the useEffect hook is not triggering it. I need assistance with this as I plan to integrate this code into my main project. Below are the JSX and CSS files attached. In App.js, I am creating ...

Using the ico-moon icon in an HTML email for various email clients such as Outlook and Gmail

I would greatly appreciate it if someone could provide instructions on how to incorporate ico-moon icons into an email HTML, ensuring they can be properly displayed in various email clients such as Outlook and Gmail. ...

In the latest version of NextJS (NextJS 13), the getServerSideProps function seems to be

I've encountered an issue with my code - console.log(data) is returning as undefined. Despite reading documentation and visiting various blogs, I can't seem to pinpoint the problem. I have confirmed that the API endpoint is functioning correctly ...

Is it possible to increase the height beyond 100% in a flexbox flex-column class div?

Recently, I utilized Bootstrap to create a grid where one of the columns contains a grid of divs. Each div is designed to expand on hover and overlap surrounding ones. These divs are equipped with images and text. On mobile devices, there are 3 divs stack ...

Material UI Card shadow effect getting cropped

Currently experiencing an uncommon issue while using Material UI's Card component - the box-shadow is cut off on the top and bottom sides. Any suggestions on how to resolve this problem? Check out my code below: import React, { Component } from & ...

Is there a way to apply the same class exclusively to the first child within a group?

How can I include specific classes for only the initial group of items in a nested ul li list? <ul> <li class="first-group"> <ul> <li></li> </ul> </li> <li class="first-group"></li> & ...