⊗tlWpAsJB 47 of 55 menu

Assets in JavaScript bundles in Webpack

Let's set up assets for .png files:

export default { entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve('dist') }, module: { rules: [ { test: /\.png$/, type: 'asset/resource' } ] }, plugins: [ new HtmlWebpackPlugin(), ], };

Let's include the .png file to the entry point:

import img from './images/main.png';

The variable img will contain the new path to the image file:

console.log(img);

Set up assets for .jpg files.

Connect multiple images to the entry point.

Display the new paths to the images in the entry point file.

enru