简体   繁体   English

为什么Webpack 2仅输出我的图像之一?

[英]Why does Webpack 2 output only one of my images?

I'm still fairly new to webpack 2 but I've got most of my configurations working so far. 我对Webpack 2还是很陌生,但是到目前为止,我的大多数配置都可以正常工作。 The only thing I'm having some difficulty understanding is that when I run "npm run build" to bundle my files into my "dist" folder I noticed that only 1 of my images are being bundled. 我唯一难以理解的是,当我运行“ npm run build”将文件捆绑到“ dist”文件夹中时,我注意到仅捆绑了一张图像。 I'm using 'file-loader'. 我正在使用“文件加载器”。 FYI all my images still show on my dev-server when I run it and appear under the public paths I assigned. 仅供参考,当我运行它时,我所有的图像仍显示在我的开发服务器上,并显示在分配的公共路径下。 It's only my local output that's not displaying all the images. 只是我的本地输出未显示所有图像。 Anyone know what's going on? 有人知道发生了什么吗?

My Folder Structure 我的文件夹结构

在此处输入图片说明

webpack.config.js webpack.config.js

module.exports = {
    mode: "development",
    entry: {
        app: "app"
    },
    output: {
        path: path.resolve(__dirname, "dist"),
        filename: "[name].bundle.js",
        publicPath: "/"
    },
    devServer: {
        publicPath: '/',
        port: 3000
    },
    module: {
        rules: [
            {
                test: /\.(png|svg|jpg|gif)$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: '[name].[ext]',
                            outputPath: 'images/',
                            publicPath: 'images/'
                        }
                    }
                ]
            }
        ]
    }
}

As you can see in my folder structure, it always builds with only one of my images being outputted. 正如您在我的文件夹结构中看到的那样,它始终仅输出我的一张图像来构建。 It's not a major issue (I don't think) since all the images still work when I run the app, but I would appreciate it if anyone could help me understand why only one image is outputting to my local 'dist'. 这不是主要问题(我不认为),因为当我运行该应用程序时所有图像仍然可以工作,但是如果有人可以帮助我理解为什么只有一个图像输出到本地“ dist”,我将不胜感激。 Thank you. 谢谢。

Webpack only writes images to disk that you require. Webpack仅将映像写入所需的磁盘。 This is one of the benefits of Webpack, it only includes assets that your application needs, so Webpack will guarantee those images exist when you deploy. 这是Webpack的优点之一,它仅包含应用程序需要的资产,因此Webpack将保证部署时这些映像存在。

To add more images to your output, require them either from your Javascript or CSS with url() s 要将更多图像添加到输出中,请通过Javascript或带有url()的CSS要求它们

Note that if you're using the dev server, Webpack doesn't write anything to disk, and keeps all compiled assets in memory. 请注意,如果您使用的是开发服务器,则Webpack不会将任何内容写入磁盘,而是将所有已编译资产保留在内存中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的程序在填写一个输入时只有 output 一个正确的数字,但如果填写了多个输入,则 output 的结果不正确? - Why does my program only output a correct number when one input is filled out, but output incorrect results if anymore inputs are filled out? 为什么webpack编译成功,但编译输出中不存在我的源代码? - Why does webpack compile successfully but my source code does not exist in the compiled output? 为什么我的一张图片没有显示在 Gatsby 页面上? - Why does one of my images not show on Gatsby page? 为什么我的 SectionList 有时只呈现一个部分? - Why does my SectionList sometimes only render one section? 为什么我的Riot.js标签中只有一个呈现? - Why does only one of my Riot.js tags render? 为什么我的事件在单击后停止发生? - Why does my event stop occuring after only one click? 为什么我的for循环只返回一个结果 - Why does my for loop return only one result 为什么我的函数只返回一个符合条件的项目? - Why does my function return only one item that matches the criteria? 为什么$ .each仅显示我的Mustache模板之一? - Why does $.each show only one of my Mustache templates? 为什么我在 onClick 中只执行了一个函数? - Why does only one of my functions in onClick execute?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM