How to fix svg-sprite-loader exception?
See original GitHub issueHow to fix: svg-sprite-loader exception. Some loaders will be applied after svg-sprite-loader in extract mode
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
svg-sprite-loader - npm
Webpack loader for creating SVG sprites. ... Start using svg-sprite-loader in your project by running `npm i svg-sprite-loader`.
Read more >Could a .svg be loaded twice in webpack? - Stack Overflow
In my vue2.0 project, I had had .svg files loaded by "svg-sprite-loader". But in iconfont I introduced .svg too, so that some .svg...
Read more >How to fix svg-sprite-loader exception? - Bountysource
How to fix : svg-sprite-loader exception. Some loaders will be applied after svg-sprite-loader in extract mode. See More.
Read more >svg-sprite-loader/CHANGELOG.md - UNPKG
606, ### Bug Fixes ; 607 ; 608, * **loader:** throw an exception if input is not valid SVG ([413246e](https://github.com/JetBrains/svg-sprite-loader/commit/ ...
Read more >Discussions - Spike
svg -sprite-loader - how to exclude SVG files from "spike loader"? ... (npm run build) I receive this warning: ModuleWarning: svg-sprite-loader exception.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I spent a whole bunch of time in order to fix this warning (i’m using symfony webpack encore).
The reason was that webpack encore has it’s default file loader for all kind of image assets and it applies it always the last.
My solution is to add in your webpack config next code:
1.Disable default image loader in order to avoid svg-sprite-loader exception:
.disableImagesLoader()
2.And then enable it again excluding the path with svg assets that i use for generate sprite in extract mode:
Hope, this will save time to somebody.
svg-sprite-loader works fine with background-image url use case. E.g. you have something like
background-image: url(path/to/yoursvg.svg
in your css, but then also icons that need to be built out in your app…I know this is closed but I too ran in to similar issues, in my case
ExtractPluginMissingException: svg-sprite-loader exception. svg-sprite-loader in extract mode requires the corresponding plugin
, but I thought I’d drop back in my notes on what definitely worked for us using svg-sprite-loader in Webpack.There are probably other options, but we use url-loader for our general image loading and for SVGs it will convert the background-image url to use a base 64 encoded. The webpack rule for our images is:
As you see we’re testing for several image types, one which is SVG. Also important is that we exclude the paths we want svg-sprite-loader (and svgo in our case) to work on.
With that, you can simply do the inverse and include those folders in your svg-sprite-loader configuration rule. So we’ve essentially got a couple of “icon directories” (handled by sprite loader and friends), and then all other directories which will get handled by our general loader.
Here’s the config I currently have for the sprite generation:
A couple of things we learned which are probably obvious but important are:
test
cases that match on the same thing e.g./\.svg$/
include
andexclude
usually work with strings, but you can use regex as we have. But, it’s very intuitive to think of these as using globbing if you’ve worked with other tools like grunt, gulp, etc., but these are strict regex! So we had the error of doing\/*\.svg
thinking that the wildcard would glob, but no, it needs to be\/.*\.svg
.But the point is it’ll totally work!
Sorry for verbose comment, but I think many folks likely have this issue like I did, but
svg-sprite-loader
will totally work in tandem with inline CSS background-image url uses and I thought it’d be useful to leave this here!