Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG loading vue-svg-loader; [Vue warn]: Invalid Component definition

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:

  1. What is my mistake?
  2. How/where can/should I add new Webpack settings
  3. or modify/overwrite/delete existing ones

in a vue-cli (V3) project?

like image 260
Lonely Avatar asked Apr 18 '18 16:04

Lonely


1 Answers

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', 
        },
      ],
    }      
  }
};
like image 119
Lonely Avatar answered Sep 19 '22 20:09

Lonely