React - imported image to base64

Viewed 577

I have question, how convert imported image in react to base64 code?

import Image from '../image.png';

to

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAF4cAAA7pCAYAAADZ6441AAAACXBIWXMAAB7BAAAewQHDaVRTAAAgAElEQVR4nOzcPXIb2XqA4Q8iqAmBHQBeAZh1CGYO7/UO0CuwJ3N2oR2MV3DGO5gVuArhyaQdwEtAORL/jgt9AVZrRpQoij
1 Answers

Because you use webpack you could use url-loader as a loader for your image. It supports importing a file by just returning its content as a data-url like you specified in your question.

Here is the offical documentation on how to use and integrate it.

Related