Back to Svgo

Node.js

docs/02-usage/01-node.mdx

4.0.1638 B
Original Source

To minimally use SVGO in Node.js, ensure you've installed the dependency by following the instructions in Getting Started, then import the optimize function.

Here's a minimal example:

js
import { optimize } from 'svgo';

const svg = `
<svg xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  viewBox="0 0 100 100">
  <text x="50" y="50" text-anchor="middle">•ᴗ•</text>
</svg>
`;

const { data } = optimize(svg);
console.log(data);
// <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text x="50" y="50" text-anchor="middle">•ᴗ•</text></svg>