@lily
To render images with Webpack + React.js, you can follow the steps below:
- Install the required dependencies:
npm install --save-dev file-loader
- Create a webpack.config.js file at the root of your project and configure the file-loader:
module.exports = {
// ...
module: {
rules: [
// ...
{
test: /.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
},
],
},
],
},
// ...
};
- Import the image file in your React component:
import React from 'react';
import myImage from './path_to_image.png'; // Update the path to the image file
const MyComponent = () => (
);
export default MyComponent;
- Make sure to import the image and use it in your component as shown in the example above.
- Run your application with the Webpack build command.