Answer the question
In order to leave comments, you need to log in
How to implement image loading with webpack loader?
Hello! Trying to smoke React.
There is a task: The image must be imported into the component and processed by the webpack loader.
Can you please explain how to implement this? What to do with him? Is there an example
Thank you
Answer the question
In order to leave comments, you need to log in
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.(png|jpe?g|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
},
},
],
},
],
},
};
import React from 'react';
import image from './image.png';
const Example = () => (
<img src={image} />
);
import React from 'react';
const Example = () => (
<img src={require('./image.png')} />
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question