Skip to content

Liquid-JS/sass-inline-svg

 
 

Repository files navigation

sass-inline-svg

GitHub license npm scope

A sass function that inlines svg files.

Installation

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

API Documentation

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

Usage

Simple example

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");
}

SVG transformation

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".

Configuring the inliner

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'
        })
    }
})

License

ISC License

About

node-sass function that inlines SVG files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 67.6%
  • TypeScript 32.4%