Assets in JavaScript bundles in Webpack
Let's set up assets for .png files:
webpack.config.jsexport 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:
src/index.jsimport img from './images/main.png';
The variable img will contain the new path to the image file:
src/index.jsconsole.log(img);
Задание 1
Set up assets for .jpg files.
Задание 2
Connect multiple images to the entry point.
Задание 3
Display the new paths to the images in the entry point file.