Webpack文件加载器仅输出PNG文件

时间:2017-02-15 16:16:00

标签: webpack webpack-2 webpack-file-loader

我目前正在尝试将现有项目合并到webpack 2.我目前正在努力解决的问题之一是文件加载器。通常,您希望它从 @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction Snooker_Scoreboard ss = new Snooker_Scoreboard(); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setCancelable(false); builder.setMessage(ss.winnerPlayer + " won the match ("+ss.frame1ToPass+"-"+ss.frame2ToPass+")!") .setPositiveButton("New Match!", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent i = new Intent(getContext(),PlayerSelection.class); startActivity(i); } }); // Create the AlertDialog object and return it Dialog dialog = builder.create(); dialog.setCanceledOnTouchOutside(false); return dialog; } <img>来源抓取所有图像文件,然后将它们放在您的dist文件夹中。

目前在我的webpack.config.js

background-image

运行webpack命令后,我的dist文件夹有一个images文件夹, only 包含PNG文件。由于某种原因,所有其他文件都被忽略。

我现在几天都在苦苦挣扎,我找不到合理解释为什么会这样。

1 个答案:

答案 0 :(得分:3)

我认为问题在于,当您需要@import这样的图像时,webpack只能通过url()const src = require('./logo.jpg');以及javascript从样式表中获取图像。 所以它不会选择在html文件中引用的任何图像,在你的情况下恰好是jpegs。

copy-webpack-plugin可能是您将这些图像也复制到dist所需的内容。