Created
June 26, 2017 14:37
-
-
Save sidonaldson/c32b3127e432176433051a43d95a2089 to your computer and use it in GitHub Desktop.
SVG Sprite Loader issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Graphic from 'component/graphic'; | |
export default const Test = (props) => { | |
const id = props.id || 'clock'; | |
return ( | |
<div> | |
<Graphic glyph={id}/> | |
</div> | |
); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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