Проблема следущая: не подгружается svg-изображения, если их вставлять в html через img.
Пример:
<img src="img/picture.svg">
Все остальные изображения лоадер грузит нормально.
Конфиг вебпака:
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const TerserJSPlugin = require("terser-webpack-plugin");
const ImageminPlugin = require('imagemin-webpack-plugin').default;
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const HtmlWebpackInlineSVGPlugin = require('html-webpack-inline-svg-plugin');
const isDev = process.env.NODE_ENV === 'development';
const isProd = !isDev;
const optimization = () => {
const config = {
splitChunks: {
chunks: "all"
}
};
if (isProd) {
config.minimizer = [new OptimizeCssAssetsPlugin(), new TerserJSPlugin()];
}
return config;
};
const fileName = ext => isDev ? `[name].${ext}` : `[name].[hash].${ext}`
module.exports = {
entry: "./src/index.js",
output: {
filename: fileName('js'),
path: path.resolve(__dirname, "dist")
},
resolve: {
extensions: [".js", ".json", ".css"]
},
optimization: optimization(),
devServer: {
contentBase: path.resolve(__dirname, "dist"),
port: 4200,
hot: isDev
},
plugins: [
new HtmlWebpackPlugin({
filename: "index.html",
template: "./src/index.html",
minify: {
collapseWhitespace: isProd
}
}),
new HtmlWebpackInlineSVGPlugin({
runPreEmit: true,
}),
new MiniCssExtractPlugin({
filename: fileName('.css')
}),
new CopyWebpackPlugin([
{
from: "./src/favicon.png",
to: path.resolve(__dirname, "dist")
}
]),
new CleanWebpackPlugin(),
new ImageminPlugin({
disable: isDev,
pngquant: {
quality: '95-100'
}
})
],
module: {
rules: [
{
test: /\.html$/i,
loader: 'html-loader',
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: isDev,
reloadAll: true
}
},
"css-loader",
"postcss-loader",
"group-css-media-queries-loader"
]
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"less-loader",
"postcss-loader",
"group-css-media-queries-loader"
]
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader",
"postcss-loader",
"group-css-media-queries-loader"
]
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
loader: "file-loader",
options: {
name(file) {
if (isDev) {
return '[name].[ext]';
}
return '[name].[hash].[ext]';
},
outputPath: "images",
esModule: false
},
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "fonts"
}
}
]
},
{
test: /\.svg$/,
loader: ['svg-inline-loader']
},
{ test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" }
]
}
};