laravel-mix: Overriding file loader rules to add exceptions
I’m using Quill in a Vue component. To avoid loading everything from the distributable build, I have prepared a quill entry file (like this one).
When doing this, however, webpack moves the svg icons used by Quill theme in /fonts/vendor/quill and returns their path, instead of returning the svg content, as Quill expects. I end up with this:

This doesn’t happen when using the distributable build in the npm package.
Quill’s build guide and related webpack example say that icons should be loaded with html loader: https://github.com/quilljs/webpack-example/blob/master/webpack.conf.js#L39
Now to my question: how can I replace/override Laravel Mix’s svg loader so it doesn’t match Quill icon paths, and instead setup html-loader just for that path?
Thanks
Edit: A past issue (closed unanswered) asks the same thing: #942.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 28 (12 by maintainers)
Since this issue is now closed I don’t expect any more replies. In the meantime, my custom solution was to add an exception to the webpack rule by cycling through Mix’s webpack configuration, like this:
I’d like a better way to do this though, the file loader regex that I’m using to find the rule could change anytime.
I also need to be able to not use Laravel Mix’s built-in SVG handling. I was able to do so building upon @tegola’s code.
First I did
console.info()on the rules to find this:It’s the second rule that does the loading of SVGs along with images.
To be able to remove the built-in SVG loading, but keep the image loading, I had to modify the regex to remove the SVG part.
Based on @tegola’s code, this is the code I wrote with which I was able to remove the built-in SVG loader so that I could use my own:
Though note that after I did this to use a loader that turns SVGs into Vue components (vue-svg-loader), SVGs linked from CSS (e.g. for background-image) don’t work anymore.
@tpraxl PR looks very nice, I’m gonna give it a spin tomorrow. Great work, thank you!
@tpraxl thanks for spending your time looking into this. I currently have no spare time to dedicate to the project, and don’t even know well webpack and laravel mix config builder, actually. I’ll keep a look at this thread and help in any possible way.
@tpraxl This seems like it: https://github.com/webpack/webpack/blob/master/schemas/webpackOptionsSchema.json#L769