Vite + Vue3 in Electron: How to import and use Material Design icons @mdi/font (or any other icon font)
P粉404539732
P粉404539732 2023-11-02 18:43:57
0
1
662

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

I installednpm i @mdi/font --save-dev:

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

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

  • Import inmain.ts:import '@mdi/font/css/materialdesignicons.css';
  • Import as scss inmain.scss:@import './node_modules/@mdi/font/scss/materialdesignicons.scss';
  • Import as css inbase.css:@import './node_modules/@mdi/font/css/materialdesignicons.css';

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

SideMenu.vue:

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

Things to consider:

  • I don't want to use the method of each icon component (don't understand this), that's because I don't use "vue-material-design-icons" or something like that
  • I don’t want to use CDN’s external links


P粉404539732
P粉404539732

reply all (1)
P粉648469285

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

  

Nothing specific to vite/vue/electron :)

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!