Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

常见问题及解决方法 (common Q&A) #2

Open
60late opened this issue Oct 25, 2023 · 5 comments
Open

常见问题及解决方法 (common Q&A) #2

60late opened this issue Oct 25, 2023 · 5 comments

Comments

@60late
Copy link
Owner

60late commented Oct 25, 2023

1.插件安装不成功(Install failed)
由于wall的原因,部分地区无法直接请求github上的镜像资源
在你全局或者项目的目录的.npmrc文件中增加以下内容

registry="https://registry.npmmirror.com"
sharp_binary_host="https://npm.taobao.org/mirrors/sharp"
sharp_libvips_binary_host="https://npm.taobao.org/mirrors/sharp-libvips"

2.打包时报错(require() of ES Module XX from XX not supported.)
是由于本插件引用的chalk,boxen等插件都是基于es module的
在package.json中加入以下代码可以解决

"type": "module",

或者,你可以把vite.config.js文件的后缀名修改为mjs,这个方法同样奏效

3.Public文件夹下的文件没有被压缩(Images in /public folder will not be compressed)
该问题已修复,把插件升级至>v1.1.0版本

4.run buid 报错Error: ENOENT: no such file or directory
该问题已修复,把插件升级至>=v1.1.3版本

@60late 60late pinned this issue Oct 25, 2023
@lish1986
Copy link

I'm using vite-vue2@1.0.0 including this plugin , the build result show error: TypeError: Intl.Segmenter is not a constructor. What happend to this? How should i fix this?

@60late
Copy link
Owner Author

60late commented Nov 29, 2023

I'm using vite-vue2@1.0.0 including this plugin , the build result show error: TypeError: Intl.Segmenter is not a constructor. What happend to this? How should i fix this?

This is an incompatibility with Node.js 14. Please consider upgrading your Runtime Node.js to 16+ (recommend v18+) @lish1986

@60late 60late changed the title 常见问题及解决方法 常见问题及解决方法 (common Q&A) Nov 29, 2023
@lish1986
Copy link

Great. It works. I upgrade Node to v16.20.0. The build speed is faster than vite-plugin-imagemin. Thanks a lot!

@yangxu52
Copy link

yangxu52 commented Jan 16, 2024

vite-plugin-compression2、vite-plugin-compression这种压缩插件,会在使用本插件转换图片格式并替换原文件之前进行压缩。

minipic({
  sharpOptions: {
    avif: {
      lossless: true,
    },
  },
  convert: [
    { from: 'webp', to: 'avif' },
    { from: 'png', to: 'avif' },
    { from: 'jpg', to: 'avif' },
    { from: 'jpeg', to: 'avif' },
  ],
})

如图所示:
image

目前解决办法是在压缩插件中排除常见的图片格式,未来是否可以解决这个问题,或者说像webp,avif等新的web图像格式已经不需要再用gz等压缩算法等去优化体积。

@60late
Copy link
Owner Author

60late commented Jan 16, 2024

vite-plugin-compression2、vite-plugin-compression这种压缩插件,会在使用本插件转换图片格式并替换原文件之前进行压缩。

minipic({
  sharpOptions: {
    avif: {
      lossless: true,
    },
  },
  convert: [
    { from: 'webp', to: 'avif' },
    { from: 'png', to: 'avif' },
    { from: 'jpg', to: 'avif' },
    { from: 'jpeg', to: 'avif' },
  ],
})

如图所示: image

目前解决办法是在压缩插件中排除常见的图片格式,未来是否可以解决这个问题,或者说像webp,avif等新的web图像格式已经不需要再用gz等压缩算法等去优化体积。

@yangxu52 你好,gzip压缩一般只针对html,css和js,一般不用于图片文件,所以未来不会增加对这方面的支持
原因可以参考这篇文章 https://zhuanlan.zhihu.com/p/664651731

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants