Skip to content

Wrong URL for background images #1380

Closed
@amlbar

Description

@amlbar

Bug report

The css-loader does not give me the correct url for my css build like when using background: url(***);. The url is being hashed automatically even setting it in file-loader option to not use a hash for the filename. I also set the file-loader option emitFile: false; and then the finished build has still emitted a file for that url. This bug exists since [email protected].

Actual Behavior

The url in my Sass file is in this form:

background: url(../../assets/img/shapes.svg);

The output url is converted to something like:

background: url(../86b5f32909e54c79331e.svg);

And the build emitted a new file 86b5f32909e54c79331e.svg with the content inside it like export default "../img/shapes.svg";

Expected Behavior

The url in my Sass file is in this form:

background: url(../../assets/img/shapes.svg);

The output url should be converted to this:

background: url(../img/shapes.svg);

And there should be no additional images created or emitted after build.

How Do We Reproduce?

You can clone my sample project with minimal code in it here in https://github.com/amlbar/webpack-build-css-with-bug and run on your local machine. For this project, you need to manually change the js and css source in the index.html. (It is handled automatically by django webpack loader in my real project)

Please paste the results of npx webpack-cli info here, and mention other relevant information

System:
    OS: Linux 4.4 Ubuntu 18.04.5 LTS (Bionic Beaver)
    CPU: (4) x64 Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
    Memory: 1.67 GB / 11.90 GB
Binaries:
    Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
    Yarn: 1.22.4 - ~/.nvm/versions/node/v12.16.3/bin/yarn
    npm: 7.24.0 - ~/.nvm/versions/node/v12.16.3/bin/npm
Packages:
    clean-webpack-plugin: ^4.0.0 => 4.0.0
    webpack: ^5.53.0 => 5.53.0
    webpack-bundle-tracker: ^1.3.0 => 1.3.0
    webpack-cli: ^4.8.0 => 4.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions