![](/img/trans.png)
[英]Webpack's file loader doesn't copy images during production from /src to /dist
[英]Webpack's file loader doesn't update path to the assets in the HTML file
所以,在我的哈巴狗模板中,我有:
img(src="../img/myimage.png", alt="image")
我在我的腳本中導入這個圖像。 它確實將文件轉到具有正確名稱和 hash 的文件夾 assets/files,但它不會更新 output HTML 文件中的 src 屬性。 它保持這樣:
<img src="../img/myimage.png" alt="image">
這是module.rules:
module: {
rules: [
{
test: /\.(html)$/,
use: {
loader: "html-loader"
}
},
{
test: /\.pug$/,
use: ["pug-loader"]
},
{
test: /(manifest.json)|(^old\/.+)|(\.(png|jpg|gif|woff|woff2|eot|ttf|otf|mp4|ico|svg|webp))$/,
use: [
{
loader: "file-loader",
options: {
name: "[name]-[hash].[ext]",
outputPath: "assets/files"
}
}
]
}
]
}
可能是什么問題?
您需要在文件加載器中設置publicPath
:
{
test: /(manifest.json)|(^old\/.+)|(\.(png|jpg|gif|woff|woff2|eot|ttf|otf|mp4|ico|svg|webp))$/,
use: [
{
loader: "file-loader",
options: {
name: "[name]-[hash].[ext]",
outputPath: "assets/files",
publicPath: "some/path"
}
}
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.