当前位置:网站首页>After downloading URL loader and specifying the size of the image with limit, the image will not be displayed
After downloading URL loader and specifying the size of the image with limit, the image will not be displayed
2022-07-27 08:23:00 【Gru 977】
Download package processing style with url Path related packages
npm i url-loader file-loader -Dadd to url-loader The rules , No report error
module: {
rules: [
{
test: /\.jpg|png|gif$/,
use: ['url-loader],
}
]
}Join in limit, To specify the size of the picture , The picture doesn't show
module: {
rules: [
{
test: /\.jpg|png|gif$/,
use: ['url-loader?limit=22228'],
}
]
}Solution steps :
1. Check out the browser Console Whether there is a wrong report ------ No error reported
2. Rerun npm run dev, Check whether the terminal reports an error ------- No error reported
3. see webpack Official website search Asset Modules , Query to :
stay webpack 5 Before , Usually use :
- raw-loader Import the file as a string
- url-loader Treat files as data URI Inline to package
- file-loader Send the file to the output directory
stay webpack 5 Using the old asset loader ( namely raw-loader/url-loader/file-loader)
- asset/inline Export asset data URI. Previously, you could use url-loader.
- asset Automatically export data URI Choose between sending a separate file . Previously, you could use
url-loaderAsset size limits .- stay webpack 5 Use the old in assets loaders ( namely
file-loader/url-loader/raw-loader) and asset's module when , You may want to stop assets loaders Deal with your assets, Because it can lead to assets repeat . This can be achieved by asset's module type Set to To complete'javascript/auto'.
To make a long story short , If you want to use webpack5, But I don't want to change the old loader The configuration file , Use old ones loader To complete the current task , Sure Add type: 'javascript/auto' To achieve .
added type: 'javascript/auto' after , No mistake. , however Still won't show pictures .
module: {
rules: [
{
test: /\.jpg|png|gif$/,
use: ['url-loader?limit=22228'],
}
],
type: 'javascript/auto'
}4. stay Asset Modules Page has url-loader, Click enter to see about url-loader Some uses of ,
With exclusion , You can get rid of some knowledge , And there are no useful setting options ,
limit: Restrictions can be specified through the loader option , The default is unlimited .
boolean: Enable or disable converting files to base64.
...
Last , unsolvable .
5. Query browser Console Report a mistake , The first time did not show , After refresh , Display error message .
![]()
6. Read the wrong information to find problems ,
(1) seek index.html:38---------- No mistake , I only 30 Line code , No, 38 That's ok
(2) lookup get The success of ---------- The whole document has no get, No report error
(3) Find the last keyword ---------[object%20Module], stay webpack Official website search object module unsolvable
(4) return 4, stay 4 See esModule( There are module, Also in the url-loader Within the scope of )
By default ,
file-loaderBuild use ES Module syntax JS modular . In some cases , Use ES Modules are useful , For example, in Module connection and Shake a tree Under the circumstances .You can enable CommonJS The module of grammar :
module.exports = { module: { rules: [ { test: /\.css$/, use: [ { loader: 'url-loader', options: { esModule: false, }, }, ], }, ], }, };
7. Look not to understand , But I tried it in the code , It is found that the picture will be displayed without error .
8. Finally, baidu searched the question [object Module], Confirm that the conjecture is correct , obtain :
esModule: false It can solve the problem of not displaying pictures .
Solution conclusion :
Add esModule: false -_-
边栏推荐
- 开怀一笑
- Netdata 性能监测工具介绍、安装、使用
- 2022-07-26 group 4 abstract classes and interfaces
- sql_ Mode strict mode (ansi/traditional/strict_trans_tables)
- 情人节,我用字符画出了一个对象!
- Leetcode54. Spiral matrix
- Vcenter7.0 managing esxi7.0 hosts
- 信息化项目风险控制与应用
- arguments
- [uni app advanced practice] take you hand-in-hand to learn the development of a purely practical complex project 1/100
猜你喜欢

1024 | in the fourth year officially called Menon, the original intention is still there, and continue to move forward

Dasctf2022.07 enabling game password WP

How to log in multiple wechat on the computer

Introduction to depth first search (DFS)

The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?
![[BJDCTF2020]EasySearch 1](/img/ea/90ac6eab32c28e09bb1fab62b6b140.png)
[BJDCTF2020]EasySearch 1

Internet of things industrial UART serial port to WiFi to wired network port to Ethernet Gateway WiFi module selection

PHP realizes data interaction with MySQL

QT creator code style plug-in beautifier

OSI seven layer model and tcp/ip four layer (TCP and UDP) (notes)
随机推荐
while Loop
1178 questions of Olympiad in informatics -- ranking of grades
【目标检测】YOLOv6理论解读+实践测试VisDrone数据集
Software test interview questions (key points)
Interviewer: what is scaffolding? Why do you need scaffolding? What are the commonly used scaffolds?
[applet] the upload of the wechat applet issued by uniapp failed error: error: {'errcode': -10008,'errmsg':'Invalid IP
redis配置文件下载
Eval and assert execute one sentence Trojan horse
Development of three database general SQL code based on PG Oracle and MySQL
opengauss从库停掉,发现主库无法写入数据
[uni app advanced practice] take you hand-in-hand to learn the development of a purely practical complex project 1/100
How to uninstall -- Qianxin secure terminal management system
PHP realizes data interaction with MySQL
QT creator code style plug-in beautifier
2020 International Machine Translation Competition: Volcano translation won five championships
如何卸载--奇安信安全终端管理系统
[pytorch] resnet18, resnet20, resnet34, resnet50 network structure and Implementation
Debug: generic related "unresolved external symbols"
arguments
Data extraction 1