/resvg-js

A high-performance SVG renderer, powered by Rust based resvg and napi-rs.

Primary LanguageRustMozilla Public License 2.0MPL-2.0

resvg-js

GitHub CI Status npm version

A high-performance SVG renderer, powered by Rust based resvg and napi-rs.

  • Very fast, safe and zero dependencies!
  • Cross-platform support, including Apple M1.
  • No need for node-gyp and postinstall, the .node file has been compiled for you.
  • Support system fonts and custom fonts in SVG text.

Installation

npm i @resvg/resvg-js
cnpm i @resvg/resvg-js
pnpm i @resvg/resvg-js

This example will load Source Han Serif, and then render the SVG to PNG.

node example/index.js

Loaded 1 font faces in 0ms.
Font './example/SourceHanSerifCN-Light-subset.ttf':0 found in 0.006ms.
✨ Done in 55.65491008758545 ms
SVG PNG

Support matrix

node12 node14 node16 npm
Windows x64 npm version
Windows x32 npm version
Windows arm64 npm version
macOS x64 npm version
macOS arm64(M1) npm version
Linux x64 gnu npm version
Linux x64 musl npm version
Linux arm gnu npm version
Linux arm64 gnu npm version
Linux arm64 musl npm version
Android arm64 npm version

Build

You can set the name of the generated .node file in napi.name of package.json.

After npm run build command, you can see resvgjs.[darwin|win32|linux].node file in project root. This is the native addon built from lib.rs.

Develop requirements

  • Install latest Rust
  • Install Node.js@10+ which fully supported Node-API
  • Install yarn@1.x

Test in local

  • yarn
  • yarn build
  • yarn test

And you will see:

$ ava --verbose

  ✔ sync function from native code
  ✔ sleep function from native code (201ms)
  ─

  2 tests passed
✨  Done in 1.12s.

Release package

We use GitHub actions to automatically publish npm packages.

# 1.0.0 => 1.0.1
npm version patch

# or 1.0.0 => 1.1.0
npm version minor

git push --follow-tags

License

MPLv2.0