[英]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.