SVG64
Convert SVG to base64 anywhere
Installation
npm install svg64
# or
yarn add svg64
Usage in browser
import svg64 from 'svg64'; // or use window.svg64.default
const svg = document.getElementById('svg');
const b64 = svg64(svg);
const demo = document.getElementById('demo');
demo.style.backgroundImage = `url(${b64})`;
Usage in NodeJS
const { resolve } = require('path');
const { readFileSync } = require('fs');
const svg64 = require('svg64');
const svg = readFileSync(resolve(__dirname, 'assets', 'example.svg'), 'utf-8');
const result = svg64(svg);
console.log(result);