Reputation:
If I want to use vue-svg-loader
in an existing vue-cli application, I get the error message
[Vue warn]: Invalid Component definition: /img/logout.b0c3dfb7.svg
Following Steps are already done:
1) Install vue-svg-loader
as devDependency
2) Add Webpack Config in vue.config.js
(root directory):
module.exports = {
configureWebpack: {
module: {
rules: [
{
test: /\.svg$/,
loader: 'vue-svg-loader',
},
],
}
}
};
3) Import SVG and inject as Component
import Logout from '@/assets/img/icons/logout.svg';
export default {
components: {
Logout,
},
...
}
4) Use it in the template (vuetify as UI-Framework)
<v-btn icon @click="logout()">
<Logout class="icon" />
</v-btn>
3 Questions:
in a vue-cli (V3) project?
Upvotes: 15
Views: 14830
Reputation: 81
In webpack.base.conf.js add the following code under rule:
{
test: /\.svg$/,
loader: 'vue-svg-loader',
}
And remove the svg from the existing below rule:
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
}
Upvotes: 4
Reputation:
Add the following into vue.config.js
:
module.exports = {
chainWebpack: config => {
config.module.rules.delete("svg");
},
configureWebpack: {
module: {
rules: [
{
test: /\.svg$/,
loader: 'vue-svg-loader',
},
],
}
}
};
Upvotes: 25