跳到主要内容

mozjpeg

imagemin 依赖安装失败

由于 imagemin 在国内安装困难,提供以下几个解决方案:

  1. 使用 yarn 在 package.json 内配置(推荐,项目内已集成,前提是必须使用 yarn)
"resolutions": {
"bin-wrapper": "npm:bin-wrapper-china"
}
  1. 使用 npm,在电脑 host 文件加上如下配置即可
199.232.4.133 raw.githubusercontent.com

使用 yarn 安装 imagemin 依赖安装失败

如果使用 yarn 还是不能安装依赖,可以将图片压缩功能移除,移除方法如下:

  • 在 package.json 内删除 vite-plugin-imagemin 这个依赖。这会导致图片没有压缩,但是可以手动到在线网站进行压缩。这里推荐tinypng
    1. 注释 vite-plugin-imagemin 插件引用
import { configImageminPlugin } from './imagemin';
VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin());

在 Linux 内依赖安装失败

如果执行 yarn install 会出现以下错误:

gifsicle pre-build test failed
compiling from source

可能是 linux 服务器需要配置下环境,imagemin 这个会导致依赖安装失败。

这里以Centos为例

  • 解决方式 1:
  1. 将以下内容添加到 yum 源
[nasm]
name=The Netwide Assembler
baseurl=http://www.nasm.us/pub/nasm/stable/linux/
enabled=1
gpgcheck=0

[nasm-testing]
name=The Netwide Assembler (release candidate builds)
baseurl=http://www.nasm.us/pub/nasm/testing/linux/
enabled=0
gpgcheck=0

[nasm-snapshot]
name=The Netwide Assembler (daily snapshot builds)
baseurl=http://www.nasm.us/pub/nasm/snapshots/latest/linux/
enabled=0
gpgcheck=0

在 /etc/yum.repos.d/ 下新建 Centos-Nasm.repo,将以上内容复制到这个文件即可

  1. 执行 yum install libtool automake autoconf nasm
  2. 重新执行 yarn install 即可

在 Linux 内使用 pnpm 安装 imagemin 依赖失败

yum install nasm
然后删除node modules
pnpm install