Answer the question
In order to leave comments, you need to log in
Why is webpack throwing an error with paths?
Webpack throws this kind of error:
Here is the config itself:
const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const PATHS = {
src: path.join(__dirname, './src'),
dist: path.join(__dirname, './dist'),
js: 'js/bundle.js',
css: 'css/style.css',
}
module.exports = {
externals: {
paths: PATHS,
},
entry: {
app: PATHS.src,
},
output: {
path: PATHS.dist,
filename: PATHS.js,
publicPath: '/',
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: '/node_modules/',
},
{
test: /\.(jpe?g|png|gif|svg)$/,
use: [
{
loader: 'file-loader',
options: {
name: "[path][name].[ext]",
}
},
{
loader: 'image-webpack-loader',
options: {
mozjpeg: {
progressive: true,
quality: 65
},
optipng: {
enabled: false,
},
pngquant: {
quality: '65-90',
speed: 4
},
gifsicle: {
interlaced: false,
},
svgo: {
enabled: false,
}
}
}
]
},
{
test: /\.less$/,
use: [
{
loader: 'style-loader',
},
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: "css-loader",
options: {
sourceMap: true,
}
},
{
loader: "postcss-loader",
options: {
sourceMap: true,
config: {
path: 'postcss.config.js',
}
}
},
{
loader: "less-loader",
options: {
sourceMap: true,
}
}
]
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: "css-loader",
options: {
sourceMap: true,
}
},
{
loader: "postcss-loader",
options: {
sourceMap: true,
config: {
path: 'postcss.config.js',
}
}
},
]
}]
},
plugins: [
new MiniCssExtractPlugin({
filename: PATHS.css,
}),
new HtmlWebpackPlugin({
hash: false,
template: `${PATHS.src}/index.html`,
filename: 'index.html',
}),
new CopyPlugin([
{
from: 'src/fonts',
to: 'fonts',
},
]),
],
}
@font-face {
font-family: 'Druk';
src: url('/../fonts/Druk-Medium.eot');
src: url('/../fonts/Druk-Medium.eot?#iefix') format('embedded-opentype'),
url('/../fonts/Druk-Medium.woff2') format('woff2'),
url('/../fonts/Druk-Medium.woff') format('woff'),
url('/../fonts/Druk-Medium.ttf') format('truetype'),
url('/../fonts/Druk-Medium.svg#Druk-Medium') format('svg');
font-weight: 500;
font-style: normal;
}
background: url(../img/img.jpg);
background: url(/img/img.jpg);
..
Answer the question
In order to leave comments, you need to log in
In fact, there is no problem, it just turned out to be the root relative path, when you upload the site to the server, everything will work.
With dots, the path is relative to the css file, and the error you most likely have is because less is in a folder inside css and webpack, when compiling, checks the paths relative to your less file, and not the future css.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question