How to modify the css img path for Webpack packaging?

the current directory structure is as follows

|--src---img-a.png
       |-scss-b.scss
       |-index.html

in b.scss

-sharpb {
    backgroun-image: url( ../img/a.png )
}

in index.html

<img src="./img/a.png">

configure webpack

module.exports = {
    mode: "production",
    entry: "./src/index.js",
    output: {
        path: path.resolve( __dirname, "dist" ),
        filename: "[name].bundle.js",
        publicPath: "./",
    },
    module: {
        rules: [
            {
                test: /\.scss$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    "css-loader",
                    "sass-loader"],
            },
            {
                test: /\.png$/,
                use: [
                    { loader: "file-loader", options: {
                        name: "img/[name].[ext]",
                    } }
                ]
            },
            {
                test: /\.html$/,
                use: {
                    loader: "html-loader",
                    options: {
                        attrs: ["img:src"]
                    }
                }
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: "./src/html/index.html",
        } ),
        new MiniCssExtractPlugin({
            filename: "css/[name].css",
            chunkFilename: "css/[id].css"
          }),
    ],
};

it is found that the img path packaged by html is. / img/a.png can be successfully accessed, but the extracted css access path is also. / img/a.png can not access the picture

how should I modify it so that index.html and css can be accessed to the same picture normally

Mar.13,2021

extracts the css portion of js to a separate file

in this case, you need to configure publicPath, to overwrite the path of the resources in it separately

use url-loader
name to define the packaged picture folder and the name of the picture

...
    {
        test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz|tmpl)(\?.+)?$/,
        exclude: /favicon\.png$/,
        use: [{
            loader: 'url-loader',
            options: {
                limit: 400,
                name: 'assets/' + (isDev ? '[name].[ext]' : '[name].[ext]?[hash:7]')
            }
        }]
    }
...
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b41580-415c8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b41580-415c8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?