Drop in angular 5 module with icon component for using svg sprites.
Guide to setting up SVG sprite based icons on an ngx project.
-
Create your SVG icons (export from Illustrator or whatever)
-
Optimise icons using SVGO https://github.com/svg/svgo
-
Install svg-sprite-generator
npm install -g svg-sprite-generator
- Generate your SVG sprite from a directory of SVG icons
svg-sprite-generate -d src/assets/icons -o src/assets/icon-sprite.svg
- Grab icon module from here https://github.com/jcjmcclean/ngx-icon-module and add into your project (probably under core module)
- Add
IconModule
in CoreModule's imports + exports - Make sure you have styling setup e.g.
svg-icon {
width: 30px;
height: 30px;
padding: 0;
border: none;
outline: none;
display: inline-block;
}
- Start using e.g.
<svg-icon name="locale-en"></svg-icon>
Resources
https://github.com/jcjmcclean/ngx-icon-module - Icon module GitHub repo
http://varun.ca/icon-component/ - Good walkthrough similar to this one but less specific to ngx