libsvgo

The core code of SVGO, optimized to be portable


License
MIT
Install
npm install libsvgo@1.3.4

Documentation

libsvgo

i:npm i:ci i:size i:npm-dev

The core code of SVGO, optimized to be portable


  • 📁 lib/ & plugins/
    • main source code, in output package will be:
      • libsvgo/lib/ & libsvgo/plugins/: for direct use, use require() / exports.*=
      • libsvgo/module/lib/ & libsvgo/module/plugins/: for use with node + @babel/register, keep import / export and readability
      • libsvgo/webpack/SVGO.js: all-in-one packaged version, can be used in browser like <script src="https://unpkg.com/libsvgo/webpack/SVGO.js"></script>, and provide window.SVGO (experimental)
  • 📁 test/
    • test code & resource file
  • 📁 examples/
    • code example

This repo is a heavily changed fork of SVGO, mainly:

  • ES6+ code update & re-format
  • drop cli and option parsing code to reduce size
  • drop node-specific module to allow both Browser and Node use

And is expected to be used by nodejs@>=12 or recent-enough Browser


sample usage: (ES6 module)

// get most used from main entry
import { SVGO, SVGO_LITE, CONFIG_LITE, PLUGINS_DEFAULT_LIST } from 'libsvgo/module/lib/svgo'

// or get each separately
import { SVGO_LITE } from 'libsvgo/module/lib/svgo-lite'
import { SVGO_LITECONFIG_LITE } from 'libsvgo/module/lib/svgo/config-lite'

// get each plugin separately
import * as addAttributesToSVGElement from 'libsvgo/module/plugins/addAttributesToSVGElement'

sample usage: (Node.js module through Babel)

// get most used from main entry
const { SVGO, SVGO_LITE, CONFIG_LITE, PLUGINS_DEFAULT_LIST } = require('libsvgo/lib/svgo')

// or get each separately
const { SVGO_LITE } = require('libsvgo/lib/svgo-lite')
const { SVGO_LITECONFIG_LITE } = require('libsvgo/lib/svgo/config-lite')

// get each plugin separately
const addAttributesToSVGElement = require('libsvgo/plugins/addAttributesToSVGElement')

sample usage: (ES6 Webpack bundle)

// `require()` in nodejs
const SVGO = require('libsvgo/webpack/SVGO')
// or load from `<script src="https://unpkg.com/libsvgo/webpack/SVGO.js"></script>` in browser

// get common lib (not all is exposed)
const { SVGO_LITE, CONFIG_LITE, PLUGINS_DEFAULT_LIST, PLUGINS_MAP } = SVGO

// get plugin
const { addAttributesToSVGElement } = PLUGINS_MAP

also check examples/ for basic usage