0

I following this post of how to setup webpack and url-loader can successfully encode the url but the image path is broken and image does not show up. I am not sure what I am doing wrong. Am I missing something obvious? Thanks for any help you can give.

webpack.config

{
        test: /\.(gif|png|jp(e*)g|svg)$/,
        use: [{
          loader: 'url-loader',
          options: {
            limit: 1000000,
            name: 'images/[hash]-[name].[ext]',
          }
        }]
}

index.js

import homeIcon from '../images/image-file.png';
var homeImg = document.getElementById('home');
homeImg.src = homeIcon;

index.html

File Structure

src
  js
    index.js
  images
      image-file.png
bilcker
  • 1,120
  • 1
  • 15
  • 43
  • Is index.js under src? I think you need: `import homeIcon from './images/image-file.png';` then – 7zark7 Dec 30 '18 at 04:01
  • thanks for your reply, The index file is under src > js > index.js I have added this to the files structure – bilcker Dec 30 '18 at 04:04

0 Answers0