M
M
Martovitskiy2019-01-07 12:47:24
Frontend
Martovitskiy, 2019-01-07 12:47:24

What is the correct way to specify Webpack file-loader publicPath with such a file structure?

Structure :
_
_
_
_
_
_
_ │ ├───img │ ├───js │ └───index.html └───webpack.config.js index.html main.sass
<img src="img/exapmle.jpg" alt="exapmle">

.home
  background: url("../img/example.jpg")

webpack.config.js
module: {
    rules: [
      {
        test: /\.(jpg|png|svg|gif)$/,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: '[name].[ext]',
              publicPath: 'img',
              outputPath: 'img',
              useRelativePath: true
            }
          },
          {
            loader: 'image-webpack-loader',
           ...
            }
          }
        ]
      }
    ]
  },

On production in dist I see only a picture from html, if I change it to publicPath: '../', then I don't see it in css
Tried the solution
publicPath: function(url) {
    return url.replace(../, '/img/')
},

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question