postcss-base64, a PostCSS plugin, replaces values inside url()
functions with their base64 encoded strings.
GitHub | NPM | @jelmerdemaat
Use
Load this plugin as a PostCSS module and give either or both of these options:
Option | Lol whut? |
---|
extensions | An array of extensions of files that have to be encoded, including the leading dot. Example: ['.svg'] |
pattern | A valid regex pattern to match against the string inside url() definitions to encode. Example: /<svg.*<\/svg>/i |
Only strings inside url(...)
functions are replaced.
Partially replacing strings with the pattern
option is possible.
NodeJS
var opts = {
extensions: ['.png', '.svg'],
pattern: /<svg.*<\/svg>/i
};
output = postcss().use(base64(opts)).process(src).css;