Ошибка при использовании картинки webpack
Структура проекта
src
-assets
-images
-pug
-includes
-mixins
-pages
В папке includes лежит навигация, в которой подключается изображение. Изображение передается в mixins.
Все это используется в pages.
Миксин
mixin image(url, name, ext)
img(src=require(`${url}${name}.${ext}`) alt=name)
Error: Cannot find module '../../assets/images/main.jpeg'
- index.pug:378 webpackContextResolve
D:/github/4 recipes-website/src/pug/pages/index.pug:378:11
- index.pug:373 webpackContext
D:/github/4 recipes-website/src/pug/pages/index.pug:373:11
- index.pug:28 Object.pug_interp [as image]
D:/github/4 recipes-website/src/pug/pages/index.pug:28:119
- index.pug:31 template
D:/github/4 recipes-website/src/pug/pages/index.pug:31:20
- index.js:450
[4 recipes-website]/[html-webpack-plugin]/index.js:450:16
- task_queues:96 processTicksAndRejections
node:internal/process/task_queues:96:5
- async Promise.all
webpack.config.js
const HtmlWebpackPlugin=require('html-webpack-plugin');
const MiniCssExtractPlugin=require("mini-css-extract-plugin");
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const PATHS = {
src: path.join(__dirname, './src'),
dist: path.join(__dirname, './dist'),
assets: 'assets/'
}
const PAGES_DIR = `${PATHS.src}/pug/pages/`
const PAGES = fs.readdirSync(PAGES_DIR).filter(fileName => fileName.endsWith('.pug'))
let mode = 'development'
if(process.env.NODE_ENV === 'production'){
mode = 'production'
}
console.log(mode + ' mode')
module.exports = {
mode: mode,
target: 'web',
devServer: {
open: true,
hot: true,
port: '9000',
static: {
directory: './src',
watch: true,
},
},
entry: {
scripts: './src/index.js',
},
output: {
filename: '[name].[contenthash].js',
assetModuleFilename: "assets/[hash][ext][query]",
clean: true,
},
devtool: 'source-map',
optimization: {
splitChunks: {
chunks: 'all',
},
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css'
}),
new webpack.HotModuleReplacementPlugin(),
...PAGES.map(page => new HtmlWebpackPlugin({
template: `${PAGES_DIR}/${page}`,
filename: `./${page.replace(/\.pug/,'.html')}`
})),
// new HtmlWebpackPlugin({
// template: './src/index.pug'
// // template: './src/[name].pug'
// })
],
module: {
rules: [
{
test: /\.html$/i,
loader: "html-loader",
},
{
test: /\.(sa|sc|c)ss$/i,
use: [
(mode === 'development') ? "style-loader" : MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
[
"postcss-preset-env",
{
// Options
},
],
],
},
},
},
"sass-loader",
],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/inline',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
{
test: /\.pug$/,
loader: 'pug-loader',
exclude: /(node_modules|bower_components)/,
},
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { targets: "defaults" }]
]
}
}
},
]
},
}
Помогите побороть напасть((