@liquid-js/sass-inline-svg

sass-inline-svg

GitHub license npm scope

A sass function that inlines svg files.

npm install @liquid-js/sass-inline-svg

https://liquid-js.github.io/sass-inline-svg/

import inlinerFunctions from '@liquid-js/sass-inline-svg'
import { compile } from 'sass'

const result = compile('styles.scss', {
functions: {
...inlinerFunctions,
// other functions
}
})
.logo-icon {
background: svg("logo.svg");
}

The inliner accepts a second argument, a map that describes transformation as { selector: { attribute: value } }.

.logo-icon {
background: svg("logo.svg", (path: (fill: green), rect: (stroke: white)));
}

In the above example all path elemens will have fill="green" and all rect elements will have stroke="white".

import { inliner } from '@liquid-js/sass-inline-svg'
import { compile } from 'sass'

const result = compile('styles.scss', {
functions: {
'svg($path, $selectors: null)': inliner('[basePath]', {
// Use SVGO to optimize the code before inlining
optimize: true,
// Encode SVG as plain data URI, which is smaller than base64 encoding (but might not be supported on legacy browsers)
encodingFormat: 'uri'
})
}
})

ISC License