Loading images with webpack
See original GitHub issueHow do I configure webpack to process <img src="local_path">
?
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (17 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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 thedata:
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.
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.