My dist folder contains my index.html, contact.html, index.js, contact.js, and two images that are mentioned by my css as background images.
ex.
background-image: url("../images/prairie.jpg");
That is everything in my dist folder. All other images(which my css does not mention) are not loaded. These images are only mentioned within .js files(ex. slideshow.js). This 'slideshow.js' file is a slideshow and it does not display any images, but shows the missing image icon. That background image mentioned earlier '../images/prairies.jpg' is shown. All the photos that are referenced by a css file are loaded into the dist folder. All photos mentioned only by a .js file and not a css file, are not loaded into the dist folder.
This is my webpack.config.js
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackTemplate = require('html-webpack-template');
const path = require('path');
const config = {
mode: 'development', // set mode option, 'development' or 'production'
entry: {
index: './src/index.js',
contact:'./src/contact.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: "[name].js",
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [
'file-loader',
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: true, // [email protected]
disable: true, // [email protected] and newer
},
},
],
}
],
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
inject: true,
chunks: ['index'],
filename: './index.html'
}),
new HtmlWebpackPlugin({
template: './contact.html',
inject: true,
chunks: ['contact'],
filename: './contact.html'
})
]
};
module.exports = config;
requirethe images.. This info might help you -> medium.com/@godban/…