Answer the question
In order to leave comments, you need to log in
How to configure webpack to display images from css?
Images that I import into components are displayed correctly. But the pictures written in the css files are not displayed.
I rummaged through everything in search of a normal config so that everything worked, but the problem remains. And the old configs that I used before do not work.
webpack.config.js
const webpack = require('webpack');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const config = {
entry: [
'react-hot-loader/patch',
'./src/index.js'
],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
plugins: [
new MiniCssExtractPlugin()
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
]
},
{
test: /\.(png|jpg|jpeg|svg|gif)$/,
include: [
path.resolve(__dirname, './dist/img/')
],
use: [{
loader: 'file-loader',
options: {
name: './dist/img/[hash].[ext]',
}
}]
},
{
test: /\.(ttf|eot|woff|woff2|png|jpg|jpeg|svg|gif)$/,
loader: 'url-loader'
}
]
},
devServer: {
'static': {
directory: './dist'
}
}
};
module.exports = config;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question