@mapbox/svg-react-transformer
Transform SVGs into JSX or React component modules.
This monorepo includes the following packages:
- @mapbox/svg-react-transformer includes the core, low-level transform functions to convert an SVG into JSX or React component modules. These functions take one string and output another string. They can be used by higher-level modules that target specific contexts, like the following ...
- @mapbox/svg-react-transformer-writer is a CLI and Node API for running SVG files through svg-react-transformer and writing the React component modules to new files. Takes an SVG file, outputs a JS file.
- @mapbox/svg-react-transformer-loader is a Webpack loader that transforms SVG files into React component modules. Allows you to
import
SVG files within Webpack-compiled JS and get a React component.
For example, given an SVG like this:
You can get a React component module like this:
Or a fancier React component module like this:
Development
npm install
to get all the dependencies and linking hooked up.
lerna bootstrap
runs in a postinstall
script.
(If you are experiencing errors, in linting or at runtime, about missing or fouled-up dependencies, you probably need to rerun installation & bootstrapping.)
Jest is installed at the top level, so you can test all repos by with npx jest
.
Release with npx lerna release
.