A webpack loader which wraps content of root element of source SVG file inside <symbol>
element and returns resulting markup.
It takes contents of root element in source SVG markup (usually, root element will be <svg>
), wraps it into <symbol>
tag and returns resulting markup.
It is possible to use another tag instead of <symbol>
using tag
loader parameter.
Attributes applied to root element in source SVG file will be preserved and applied to target <symbol>
tag.
If source SVG image contains elements with id
attribute set, loader will append unique prefix to all id
s in order to make them unique in the universe.
There may be different usage scenarios for different people. One of them is described below.
Usually data:URI
scheme is used to embed icons in SVG file. That results in SVG file containing urls with data:URI
scheme.
Although support for such url scheme is pretty good, some SVG parsers do not understand such urls. For example, Apache Batik fails to rasterize SVG markup including urls with data:URI
to PDF.
If embedded icon is SVG itself, it can be included by copy/pasting its markup into target SVG file.
In order to point to inserted element, it should have an id
attribute assigned, which can be assigned using id
loader parameter.
The loader supports the following parameters:
Defaults to symbol
. Is used as the name of root tag in generated SVG markup.
If given, will be applied to the root tag (symbol
by default, see description for tag
option) in generated SVG markup.
If given, will be applied to the root tag in generated SVG markup.
If given, overwrites value of viewBox
attribute applied to the svg
tag in source SVG file.
If given, overwrites value of height
attribute applied to the svg
tag in source SVG file.
If given, overwrites value of width
attribute applied to the svg
tag in source SVG file.
If given, overwrites value of preserveAspectRatio
attribute applied to the svg
tag in source SVG file.
Parameters can be passed both in a url or from webpack config file. See Using loaders section in webpack documentation for more details.
The id
and class
parameters allow naming templates based on filename interpolation. See loader-utils#interpolatename
for full usage details.