WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Using this to display SVG's as a base64 string in an image src. (example/question) #89

@Pixelatex

Description

@Pixelatex

So I had some issue figuring out how this was supposed to be used and I managed to make it work but I'm not it's the correct usage.

I'm using this to load images in a component library built with react and storybook.

webpack.config.js

{
    test: /\.svg$/,
    loader: 'svg-inline-loader',
},

usage:

import Logo from '../../assets/logo.svg';

const convertSvgToBase64ImgString = SVG => `data:image/svg+xml;base64,${Buffer.from(SVG).toString('base64')}`;

const Result = () => (
    <img src={convertSvgToBase64ImgString(Logo)} />
);

I wondered if there was no way to have it return base64 straight from the webpack loader but I couldn't figure it out so I did a base64 encode myself.

This is both to maybe help others with this issue / to check if I could do this in a more efficient way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions