B
B
bra1nf00d2021-04-06 13:55:04
Node.js
bra1nf00d, 2021-04-06 13:55:04

What is the problem with webpack 4 image paths?

The error occurred after processing the scss files.
The problem is in the paths, how the image is inserted into the html, not suitable for css files
I tried to change the name, at the time of uploading the files, but again.

Tell me how you can solve this problem without resorting to url-loader

I work with webpack-dev-server, at startup the project folder is cleared, there is nowhere to link to it

Working link in styles:
606c38e34cad2762427340.png

Broken:
606c38d85897d779697330.png

---

Working path in html: Broken
606c3ac0c80cf775500561.png

:
606c3ac8b40ae012224972.png

Webpack :

/* IMG */
{
    test: /\.(png|jpe?g|gif|svg)$/,
      use: [
    {
      loader: 'file-loader',
      options: {
        name: `img/${filename('[ext]')}`,
        esModule: false,
        publicPath: ''
      }
    }
  ],
},

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bra1nf00d, 2021-04-17
@bra1nf00d

I found a solution.
In the mini-css-extract-plugin plugin, you can pass publicPath options: '../'
At the output, I get a customized path in .scss, and keep the same path in html

{
test: /\.(s[ac]ss|css)$/,
        use: [
          {loader: MiniCssExtractPlugin.loader, options: {publicPath: '../'} },
          {loader: 'css-loader'},
          {loader: 'sass-loader'},
        ]
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question