升级vue应用程序后,require()方法的不同输出
我有一个带有webpack
和旧babel
版本的vue应用程序。当我将其升级到vue-cli
和new @babel
时,它为图像输出意外结果。
以下代码结果不同输出:
require('./assets/logo.png')
旧应用程序(必需)输出:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5c...
新的更新输出:
/img/logo.82b9c7a5.png
我不确定是否是由于vue-cli
或@babel
或任何其他依赖关系。请帮助我找出这个问题。 我在GIT中推出了这2个应用程序的基本样板。
- webpack
- with vue-cli appp
I've a Vue Application with webpack
and old babel
version. When I upgraded it to vue-cli
and new @babel
, it output unexpected result for images.
Following Code results different output:
require('./assets/logo.png')
Old Application (Required) Output:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5c...
New Update Output:
/img/logo.82b9c7a5.png
I'm not sure, whether it is due to the vue-cli
or @babel
or any other dependencies. Please help me to figure out this problem.
I've pushed basic boilerplate for these 2 applications in Git.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
VUE CLI 5不使用
url-loader
和file-loader
您需要使用此代码:
ps:set
maxsize
to- 1
如果要存储文件而不是它们的哈希Vue CLI 5 does not use
url-loader
andfile-loader
You need to use this code:
PS: set
maxSize
to-1
if you want to store the files instead of their hashesVUE CLI 4使用
url-loader
图像URL(专门用于*。PNG
,*。jpg
,*。jpeg
,*。
*。WebP
)。如果导入的图像在尺寸限制范围内,则将图像列为数据URL 。否则,它将传递到file> file-loader
,将已解决的路径URL返回到文件中。vue cli使用a 固定的内联限制设置为4096字节
url-loader
。 logo示例中的徽标是6849 bytes bytes ,超过内联限制,导致其作为路径URL加载。您可以使用以下 vue cli config file (需要在您的情况下创建):
Vue CLI 4 uses
url-loader
for image URLs (specifically for*.png
,*.jpg
,*.jpeg
,*.gif
, and*.webp
). If an imported image is within a size limit, the image is inlined as a data URL. Otherwise, it's passed ontofile-loader
, which returns the resolved path URL to the file.Vue CLI uses a fixed inline limit set at 4096 bytes for the
url-loader
. The logo in your example is 6849 bytes, which exceeds the inline limit, causing it be to loaded as a path URL.You can change the inline limit with the following Vue CLI config file (needs to be created in your case):