批次壓縮目錄:1 行 vs 多行
Sharp (Node.js)
import sharp from 'sharp';
import fs from 'fs/promises';
import path from 'path';
// Convert every image in a directory to WebP
const dir = './images';
const out = './out';
const files = await fs.readdir(dir);
const images = files.filter(f => /\.(jpe?g|png|gif)$/i.test(f));
await Promise.all(
images.map(file =>
sharp(path.join(dir, file))
.webp({ quality: 80 })
.toFile(path.join(out, file.replace(/\.[^.]+$/, '.webp')))
)
);GetWebPRecommended
# One command — that's it getwebp ./images -o ./out
✓ ✓ 無需迴圈,無需非同步檔案處理,無需額外設定。
架構:WASM 引擎 vs 原生繫結
核心差異在於圖像處理發生的位置及其相依關係。
Pure WASM
GetWebP — 純 WASM
附帶從專用編解碼器編譯的自包含 WebAssembly 二進位檔。在 Node.js、Deno、Cloudflare Workers、Vercel Edge 和瀏覽器上執行完全一致。無需建置工具、無需系統套件、無需變更 Docker 層。
Native Bindings
Sharp — libvips C++ 繫結
透過原生 Node.js 繫結封裝 libvips C 函式庫。為 Node.js 伺服器上的 CPU 密集型工作負載提供出色的吞吐量。安裝時需要原生編譯,與 Edge 執行環境或瀏覽器不相容。
功能比較
滑動查看完整表格 →
功能
Sharp
推薦GetWebP
安裝方式
npm install sharp (+ native compile)
Single binary / npm install
安裝方式
Sharpnpm install sharp (+ native compile)
GetWebPSingle binary / npm install
Node.js 支援
Node.js 支援
Sharp
GetWebP
Edge / 無伺服器支援
Edge / 無伺服器支援
Sharp
GetWebP
瀏覽器支援
瀏覽器支援
Sharp
GetWebP
原生相依性
libvips (native)
None (WASM)
原生相依性
Sharplibvips (native)
GetWebPNone (WASM)
Docker 映像檔大小影響
+50–100 MB
+~5 MB
Docker 映像檔大小影響
Sharp+50–100 MB
GetWebP+~5 MB
易用性(批次任務)
Loop + async pipeline
1 CLI command
易用性(批次任務)
SharpLoop + async pipeline
GetWebP1 CLI command
效能概覽
安裝時間GetWebP:下載即執行。Sharp:npm install + 原生編譯。
GetWebP
Sharp
記憶體佔用GetWebP WASM 沙箱 vs Sharp libvips 進程記憶體。
GetWebP
Sharp
冷啟動延遲WASM 與原生二進位載入在 Edge / 無伺服器環境下的冷啟動比較。
GetWebP
Sharp
常見問題
本比較反映了我們截至 2025 年初對各工具已記載功能的理解。Sharp 是一個維護良好、廣泛使用的函式庫。我們力求準確呈現差異——如有錯誤,請告知我們。