search

Home  >  Q&A  >  body text

Vite + Vue3 in Electron: How to import and use Material Design icons @mdi/font (or any other icon font)

I want to bundle @mdi/font icons into my app (it's an Electron app).

I installed npm i @mdi/font --save-dev:

  "devDependencies": {
    "@mdi/font": "^7.0.96",
  }

Then I imported the css/scss and I tried a few different methods:

Then I used mdi-* css classes in the markup:

SideMenu.vue:

<template>
  <aside class="menu">
    <ul class="action-bar">
      <li class="action-item active">
        <a class="action-label icon">
          <i class="mdi-cog"></i>
        </a>
      </li>
      <li class="action-item">
        <a class="action-label icon">
          <i class="mdi-home"></i>
        </a>
      </li>
      <li class="action-item">
        <a class="action-label icon">
          <i class="mdi-content-copy"></i>
        </a>
      </li>
    </ul>
  </aside>
</template>

The application starts and runs but I see the same icon.

Things to consider:


P粉404539732P粉404539732414 days ago900

reply all(1)I'll reply

  • P粉648469285

    P粉6484692852023-11-03 14:03:05

    Answering my own question. Thanks @Duannx, the solution is very simple - just add the missing mdi class:

    <a class="action-label icon">
      <i class="mdi mdi-cog"></i>
    </a>
    

    Nothing specific to vite/vue/electron :)

    reply
    0
  • Cancelreply