tl;dr:
- Node.js >= 6 is required.
nameoption was renamed tosymbolId.regExp,prefixize,angularBaseWorkaroundoptions was removed and will have no effect. Prefixize applies for symbol elements by default. Workaround for Angular enables automatically when'angular' in window === true.- Runtime API has changed, but compatible mode available via
runtimeCompat: true.
In most cases following config should work:
// webpack 1
module.exports = {
module: {
loaders: [
{
test: /\.svg$/,
loader: 'svg-sprite-loader?runtimeCompat=true'
}
]
}
}
// webpack 2
module.exports = {
module: {
rules: [
{
test: /\.svg$/,
loader: 'svg-sprite-loader',
options: {
runtimeCompat: true
}
}
]
}
}Some magic now happens by default, viz:
- Used runtime module depends on webpack 'target' config option: browser sprite module will be used for 'web' target, and isomorphic sprite module for all other targets.
- Loader switches in extract mode automatically if SVG image was imported from css/scss/html etc (see EXTRACTABLE_MODULE_ISSUER_PATTERN).
- Generated export format depends on webpack version,
module.exports = ...for webpack 1,export default ...for webpack 2.
- Sprite/symbol generator was moved to separate project svg-baker and fully reworked.
-
New runtime API. Instead of symbol id runtime module now returns an object (class instance actually) which contains
id,viewBoxandcontentfields. Reason: make runtime more flexible, also it was requested in #32.// old import symbolId from './image.svg'; // symbolId === '#image' const rendered = ` <svg> <use xlink:href="${symbolId}" /> </svg>`; // new import symbol from './image.svg'; // symbol === SpriteSymbol<id: string, viewBox: string, content: string> const rendered = ` <svg viewBox="${symbol.viewBox}"> <use xlink:href="#${symbol.id}" /> </svg>`;
If you need old behaviour, set
runtimeCompatoption totrue. -
Sprite/symbol javascript runtime was moved to separate project svg-baker-runtime and fully reworked.
-
Added ability to specify custom runtime generator via
runtimeGeneratoroption (check default runtime generator for example). -
Runtime symbol is an object now (class instance actually). It contains
id,viewBoxandcontentfields. See SpriteSymbol class. Fixes #32. -
Base URL fix in
styleattributes (svg-baker-runtime@efd32). Fixes #7. -
Encode special chars in url when modifying attributes (svg-baker-runtime@efd32). Fixes #79.
- Extract sprite as separate file done right! See example. Fixes #66, #73, #83.
- Ability to extract multiple separate sprites by webpack loader config (example will be soon).
- Ability to extract sprite for each chunk, like extract-text-webpack-plugin (example will be soon). Experimental feature, should be used with caution.