react-transform-svgify
Transform SVG files into React elements.
This is a fork of svg-reactify
Configuration
As with most browserify transforms, you can configure it via the second argument to bundle.transform
:
bundle;
or inside your package.json
configuration:
Requiring SVG files
Now you can do things like...
var React = SVG = Dog : Parrot: Horse : ; moduleexports = React;
Templates
react-transform-svgify uses templates to produce the react components. Currently there are two templates available - image
and icon
. Maybe there will be more in the future, like one for symbols for example.
Choose the default template using the default
option. You can also set a regex for choosing templates based on filename like:
This will use the image
template by default and icon
if the filename matches the regex \.icon
. The other way around would be for example ["react-transform-svgify", { "default": "icon", "image": "\.image" }]
.
Icon Template
This template will produce a DOM tree looking like:
The <span>
element will also inherit any props given to the element, for example the following react element:
... will override the default class and produce:
You could then style the svg element further through CSS, for example:
Image Template
This template will produce a DOM tree containing only the SVG:
It will NOT pass on any props given to the element, so you cannot set the className or such.