dff95fce56741000b7c3f4187abab363134bd81f3b27979c41517d6144c00a2af68dad1633f3600c168f9ed4d448d8d967cad881c663a26c8f465a903683bd 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Extracted sprite example
  2. Extract SVG sprite as separate file with `extract: true` option (see [webpack config](webpack.config.js)).
  3. When loader is in extract mode, the returning value is extracted sprite file URL with symbol id at the end, e.g. `sprite.svg#symbolId`.
  4. This makes possible to use [SVG stacking technique](https://css-tricks.com/svg-fragment-identifiers-work/#article-header-id-4) which
  5. [supported by most of browsers](http://caniuse.com/#feat=svg-fragment) except of Safari (both desktop and mobile) and Android browser prior to 4.4.4.
  6. ### [Demo](build/main.html)
  7. ### Import from JS
  8. [Input](main.js)
  9. ```js
  10. import './logo.svg';
  11. ```
  12. [Output](build/main.js#L87)
  13. ```js
  14. module.exports = 'sprite.svg#logo-usage';
  15. ```
  16. ### Import from CSS
  17. [Input](main.css)
  18. ```css
  19. .logo {background: url('./logo.svg')}
  20. ```
  21. [Output](build/main.css)
  22. ```css
  23. .logo {background: url('sprite.svg#logo-usage')}
  24. ```
  25. ### Import from HTML
  26. [Input](main.html)
  27. ```html
  28. <img src="./logo.svg" alt="">
  29. ```
  30. [Output](build/main.html)
  31. ```html
  32. <img src="sprite.svg#logo-usage" alt="">
  33. ```
  34. - [sprite.svg](build/sprite-c9cbc8.svg)
  35. - [main.html](build/main.html)
  36. - [main.css](build/main.css)
  37. - [main.js](build/main.js)