我正在尝试使Webpack 4将.jpg文件输出到/ dist / img,并通过文件加载器和html-webpack-plugin将其用于index.html文件。
.jpg文件确实输出到dist / img中,但是没有加载到index.html中,输出index.html看起来像这样。 enter image description here
下面是来自webpack.config.js的代码,我认为与该问题有关,
const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: "development",devtool: "source-map",entry: {
main: "./src/js/index.js"
},output: {
filename: "[name].js",path: path.resolve(__dirname,"dist")
},plugins: [
new HtmlWebpackPlugin({
template: "./src/template.html"
})],module: {
rules: [
{
test: /\.css$/,use: [
"style-loader",{
loader: "css-loader",options: {
sourceMap: true
}
}
]
},{
test: /\.html$/,use: ["html-loader"]
},{
test: /\.(png|jpg|gif|eot|ttf|woff|woff2)$/,loader: 'file-loader',options: {
name: '[name].[ext]',outputPath: './assets'
}
}
]
}
};