Skip to content

Instantly share code, notes, and snippets.

@sidonaldson
Created June 26, 2017 14:37
Show Gist options
  • Save sidonaldson/c32b3127e432176433051a43d95a2089 to your computer and use it in GitHub Desktop.
Save sidonaldson/c32b3127e432176433051a43d95a2089 to your computer and use it in GitHub Desktop.
SVG Sprite Loader issue
const Graphic = (props) => {
const {glyph, ...rest} = props;
let svg = null;
try {
svg = require('../../assets/svg/' + glyph + '.svg').default;
} catch (err) {
return null;
}
return (
<svg {...rest} viewBox={svg.viewBox}>
<use xlinkHref={svg.url}/>
</svg>
);
};
export default Graphic;
import Graphic from 'component/graphic';
export default const Test = (props) => {
const id = props.id || 'clock';
return (
<div>
<Graphic glyph={id}/>
</div>
);
};
rules: [
{
test: /\.svg$/,
loader: 'svg-sprite-loader',
options: {
extract: true,
spriteFilename: 'svg-sprite.svg'
}
}
];
};
...
plugins: [
new SpriteLoaderPlugin()
]
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment