Resolve-url-loader没有解析我的css 文件中的图像/字体。我的文件夹结构是这样的:
src
public
images
-banner-bg.jpg
stylesheets
css
-basic.css with background: url(../../images/banner-bg.jpg)
scss
-main.scss with @import "../css/basic.css";
输出文件夹:
dist
public
images
-banner-bg.jpg
stylesheets
-main-output.css
图像和字体在开发服务器中显示正常,并在生产中正确复制。main-output.css -检查时 - 显示
background:url(public/images/banner-bg.jpg
而不是预期的
background:url(../images/banner-bg.jpg)
浏览器控制台显示错误:
GET file: ///home/ustrd/Documents/myproject12/dist/public/stylesheets/public/images/banner-bg.jpg net:: ERR_FILE_NOT_FOUND
plugins: [
new MiniCssExtractPlugin({
filename: path.join("public", "stylesheets", "[name].css")
})
],
module: {
rules: [
{
test: /\.(css|scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
sourceMap: true,
importLoaders: 2
}
},
{
loader: "postcss-loader",
options: {
ident: "postcss",
plugins: () => [new PostcssPresetEnv()]
}
},
{
loader: "resolve-url-loader",
options: { sourceMap: true }
},
{ loader: "sass-loader", options: { sourceMap: true } }
]
},
任何想法如何解决这个问题?