Vue Cli defaults to file-loader
for SVG assets, but I want to use svg-sprite-loader
(as well as a few others) instead.
I updated the vue.config.js
file to do this and it still seems to use file-loader
. Almost as though it's not picking up my config at all.
vue.config.js
module.exports = {
configureWebpack: {
module: {
rules: [
{
test: /\.(svg)(\?.*)?$/,
use: [
{
loader: 'svg-sprite-loader',
options: {
name: '[name]-[hash:7]',
prefixize: true
}
},
'svg-fill-loader',
'svgo-loader'
]
}
]
}
}
}
Is there anything wrong with my setup?
I'm still getting SVG files imported into my component as a URL string / path when it should be an object with properties.
Many thanks.
Vue CLI docs for version 3.x in webpack section suggests to use something like this:
Even vue-svg-loader configuration guide suggests same approach.
The Webpack docs for Vue CLI 3.0 beta got updated with an example on how to replace an existing Base Loader. For
svg-sprite-loader
this means that you'll have to add the following configuration to yourvue.config.js
:This took me a while to find a work around. Basically you need to stop file-loader matching on .svg. The best way I have found to do this is using chainWebpack and returning false from the test method on file-loader. I have included my working config.
I'm using Vue CLI 3.0.3 and this config works for me