Webpack 4文件加载器不适用于图像

我正在尝试使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'
                }
            }
        ]
    }
};
yxj7078 回答:Webpack 4文件加载器不适用于图像

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2946572.html

大家都在问