question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loading images with webpack

See original GitHub issue

How do I configure webpack to process <img src="local_path">?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:18 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
Sayan751commented, Mar 6, 2021

@DennisDyallo Here is a minimalistic example of what I meant. https://github.com/Sayan751/au2-webpack-img-demo

Note that there are 2 images one small and another is large. The images are imported as follows:

https://github.com/Sayan751/au2-webpack-img-demo/blob/d3a3296ace80dbc1756b69dab08637eb78f6a7e9/src/app.ts#L3-L10

And used like this

https://github.com/Sayan751/au2-webpack-img-demo/blob/d3a3296ace80dbc1756b69dab08637eb78f6a7e9/src/app.html#L1-L10

Depending on your webpack config, the images are loaded using the http: scheme or the data: scheme (for smaller images).

https://github.com/Sayan751/au2-webpack-img-demo/blob/d3a3296ace80dbc1756b69dab08637eb78f6a7e9/webpack.config.js#L30

When you build the app, this is how the output looks like. Note that the larger image name is replaced with webpack-friendly id.

image

1reaction
3cpcommented, Feb 25, 2021

I think our webpack loader should support the result of html-loader, so that we can chain them. Let the html-loader process it first, then our loader. I will get back to you on this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asset Management
Loading Images · import _ from 'lodash'; import './style.css'; · import Icon from './icon.png'; · function component() { const element = document.
Read more >
Load images and fonts with Webpack file loader like a pro
Webpack file-loader is a loader used mainly for supporting images such as SVG and PNG, and fonts in your webpack project. If your...
Read more >
How to load image files with webpack file-loader
I am using webpack to manage a reactjs project. I want to load images in javascript by webpack file-loader . Below is the...
Read more >
Loading Images
Webpack allows you to load images dynamically based on a condition. The techniques covered in the Code Splitting and Dynamic Loading chapters are...
Read more >
Images with Webpack
You may wonder why we must use Webpack to display an image on our site. Well, Webpack is a module bundler. It takes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found