Wednesday, August 18, 2021

Compiling dom-to-svg

This is about compiling dom-to-svg, but it probably applies to most libraries that are set up for a webpack build process.
  1. create ./src and ./dist dirs
  2. create index.html in dist
  3. install libraries npm install --save dom-to-svg etc.
  4. set up package.json like here https://webpack.js.org/guides/getting-started/
  5. create src/index.js and refer to the libraries in it import { documentToSVG, elementToSVG, inlineResources, formatXML } from 'dom-to-svg'
  6. run webpack npx webpack
a minimal index.js is as follows: import { documentToSVG, elementToSVG, inlineResources, formatXML } from 'dom-to-svg' window.domToSVG = {} domToSVG.documentToSVG = documentToSVG domToSVG.elementToSVG = elementToSVG domToSVG.inlineResources = inlineResources domToSVG.formatXML = formatXML