gpt4 book ai didi

javascript - 此浏览器不支持 Webpack5 自动 publicPath

转载 作者:行者123 更新时间:2023-12-03 06:50:51 27 4
gpt4 key购买 nike

我正在使用 webpack 4.44.2,当我转换为 webpack5.0.0 时遇到此错误
./src/assets/sass/styles.scss 中的错误
模块构建失败(来自 ./node_modules/mini-css-extract-plugin/dist/loader.js):
错误:此浏览器不支持自动 publicPath
在 E:\maktab\Control-panel\newcontrol\final-control\node_modules\css-loader\dist\cjs.js!

错误来自 fonts.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;
}

我的 src 结构
/image/vKyfW.png
分布结构
/image/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({}),
]

}

样式.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");

最佳答案

建议的解决方案对我不起作用。但是,我发现设置 publicPath到一个空字符串就可以了。

output: {
publicPath: '',
...
}

关于javascript - 此浏览器不支持 Webpack5 自动 publicPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64294706/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com