Answer the question
In order to leave comments, you need to log in
How to correctly set paths in file-loader?
Hello! I have the following structure in /src
| index.html
+---css
| style.css
+---img
| image.jpg
and here is the config:
const path = require(`path`);
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
mode: `development`,
entry: `./src/index.js`,
output: {
filename: `[name].js`,
path: path.join(__dirname, `public`)
},
optimization: {
splitChunks: {
name: 'vendor',
chunks: 'all',
},
},
plugins: [
...['index','catalog'].map((event) => {
return new HtmlWebpackPlugin({
template: `./src/${event}.html`,
filename: `${event}.html`,
})
}),
new MiniCssExtractPlugin({
filename: 'css/[name].css',
})
],
devtool: `source-map`,
devServer: {
contentBase: path.join(__dirname, `public`),
publicPath: `http://localhost:8080`,
hot: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
},
{
test: /\.(css|scss)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
'css-loader',
'sass-loader',
]
},
{
test: /\.(jpe?g|png|gif|svg)$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'img',
publicPath: '../img',
}
}
},
]
}
};
background-image: url("../img/modal-map.jpg");
<img src="<%= require('./img/slide.jpg') %>">
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