Je travaillais sur Webpack 4.44.2, je suis confronté à cette erreur lorsque je conversé au webpack5.0.0
Erreur dans ./src/assets/sass/styles.scss Module Build Build (à partir de ./node_modules/min-csss-extract-plugin/dist/loader.js): Erreur: Automatique PublicPath N'est pas pris en charge dans ce navigateur à E:\MakTab\Control-Panel\NewControl\Final-Control\Node_Modules\css-loader\dist\cjs.js!
l'erreur provient du bain de fichiers de polices dans Fontss.scss
@font-face {
font-family: "Janna LT";
src: local("Janna LT"), url(../fonts/janna.woff) format("woff");
font-weight: normal;
}
@font-face {
font-family: "Janna LT";
src: local("Janna LT"), url(../fonts/janna-bold.woff) format("woff");
font-weight: bold;
}
ma structure SRC https://i.stack.imgur.com/vkyfw.png
dist structure https://i.stack.imgur.com/mlgmf.png
webpack.config.js
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
entry: {
'main': './src/index.js',
},
output: {
path: path.join(__dirname, "/dist"),
filename: '[name].js',
},
devServer: {
contentBase: path.join(__dirname, "/dist"),
port: 8087,
writeToDisk: true,
overlay :true
},
module: {
rules: [
{
test: /\.html$/,
use: [
{
loader: "html-loader",
}
]
},
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader'
]
},
{
test: /\.(png|svg|jpe?g|gif)$/,
exclude: /fonts/,
use: [
{
loader: "file-loader",
options: {
name: '[name].[ext]',
outputPath: "/assets/images",
}
}
]
},
{
test: /\.(svg|eot|woff|woff2|ttf)$/,
exclude: /images/,
use: [
{
loader: "file-loader",
options: {
name: '[name].[ext]',
outputPath: "assets/fonts",
}
}
]
},
]
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
filename: "index.html",
template: "./src/index.html",
chunks: ['main']
}),
new MiniCssExtractPlugin({filename: "assets/css/styles.css"}),
new OptimizeCSSAssetsPlugin({}),
]
}
styles.scss
@import "base/fonts";
@import "base/global";
@import "base/typography";
@import "base/links";
@import "components/components";
@import "components/demo";
index.js
import './assets/sass/styles.scss';
import 'normalize.css/normalize.css';
console.log("hellow from webpack5");
Je pense que ce sera utile que l'on ajoute publicPath
au options
de MiniCssExtractPlugin.loader
référence: mini-CSS-extrait-extrait-plugin
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '/public/path/to/',
},
},
'css-loader',
],
},
],
},