img(src=require(...)) 生成丑陋的 html
img(src=require(...)) generates ugly html
我已经编写了包含以下内容的 pug 文件:
img(src=require("../../assets/icons/icon.png"))
并尝试通过 Webpack 使用下一个 Webpack 配置将其构建为 html:
module: {
rules: [
{
test: /\.pug$/i,
use: {
loader: 'pug-loader',
options: {
pretty: true
},
},
},
....
{
test: /\.(png|jpg|svg|jpeg|gif)$/,
exclude: [
/Montserrat-Bold.svg$/,
/Montserrat-Regular.svg$/,
/Quicksand-Regular.svg$/,
],
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "assets/icons/",
publicPath: '../assets/icons/'
}
}
]
},
.....
因此它内置于
<img src="{"default":"../assets/icons/icon.png"}">
当我打开包含此内容的 html 页面时,图像未加载。
我应该怎么做才能将 img(src=require("../../assets/icons/icon.png"))
构建成 <img src="../assets/icons/icon.png">
?
需要在文件加载器选项中添加esModule: false
:
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "assets/icons/",
publicPath: '../assets/icons/',
esModule: false,
}
}
]
我已经编写了包含以下内容的 pug 文件:
img(src=require("../../assets/icons/icon.png"))
并尝试通过 Webpack 使用下一个 Webpack 配置将其构建为 html:
module: {
rules: [
{
test: /\.pug$/i,
use: {
loader: 'pug-loader',
options: {
pretty: true
},
},
},
....
{
test: /\.(png|jpg|svg|jpeg|gif)$/,
exclude: [
/Montserrat-Bold.svg$/,
/Montserrat-Regular.svg$/,
/Quicksand-Regular.svg$/,
],
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "assets/icons/",
publicPath: '../assets/icons/'
}
}
]
},
.....
因此它内置于
<img src="{"default":"../assets/icons/icon.png"}">
当我打开包含此内容的 html 页面时,图像未加载。
我应该怎么做才能将 img(src=require("../../assets/icons/icon.png"))
构建成 <img src="../assets/icons/icon.png">
?
需要在文件加载器选项中添加esModule: false
:
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "assets/icons/",
publicPath: '../assets/icons/',
esModule: false,
}
}
]