在Termux中编译Nodejs库sharp

有一个 Nodejs 项目使用到了图形处理库 sharp,但是想在 termux 中使用必须自行编译。关于 sharp 的介绍在这里不再阐述,想了解的可以去看项目主页和文档。下面给出编译方法。

编译步骤

1.下载项目到 Temux

如果手机上还没有 termux,请先安装 termuxnodejs 环境:termux的使用方法总结

1
2
3
4
5
6
7
8
# 安装 wget
$ pkg install wget

# 下载项目
$ wget -O sharp.zip https://github.com/lovell/sharp/archive/refs/tags/v0.32.1.zip

# 解压
$ unzip sharp.zip

2.安装编译环境

1
2
3
# sharp 使用 node-gyp 来编译原生插件,依赖 libvips 和 python
# https://github.com/termux/termux-packages/issues/5211
$ pkg install pkg-config binutils xorgproto libvips python2

3.执行编译

1
2
3
4
$ cd sharp-0.32.1

# 执行 npm install 会自动安装项目依赖并编译项目
$ npm install

编译成功后会在项目目录下生成 build/Realease/sharp-android-arm64v8.node 文件


在Termux中编译Nodejs库sharp
https://blog.itfox.net/posts/在termux中编译nodejs库sharp.html
作者
blog.itfox.net
发布于
2023年6月10日
许可协议