icons icon indicating copy to clipboard operation
icons copied to clipboard

Icon font regression when using Vite

Open cernyjakub opened this issue 2 years ago • 16 comments

Hello!

I have been using icon font in Vite by simpley including 1 line in my SCSS file:

@import 'bootstrap-icons/font/bootstrap-icons';

After updating to 1.9, this is no longer working. I assume it is related to changes of font-path variables, hashes, etc. - as mentioned in #1378.

It would be super-cool to keep this compatibility.

cernyjakub avatar Jul 20 '22 09:07 cernyjakub

Very likely, this is related to https://github.com/vitejs/vite/issues/7651 - Vite SASS processor is unable to peoperly rebase url() when there are variables in it (if I understand correctly).

So move from (1.8.3):

$bootstrap-icons-font-src: url("./fonts/bootstrap-icons.woff2?08efbba7c53d8c5413793eecb19b20bb") format("woff2"),
url("./fonts/bootstrap-icons.woff?08efbba7c53d8c5413793eecb19b20bb") format("woff") !default;

to (1.9)

$bootstrap-icons-font-src: url("#{$bootstrap-icons-font-file}.woff2?#{$bootstrap-icons-font-hash}") format("woff2"), url("#{$bo
otstrap-icons-font-file}.woff?#{$bootstrap-icons-font-hash}") format("woff") !default;

killed the Vite importer.

As a workaround, we can import the generated CSS like this:

@import 'bootstrap-icons/font/bootstrap-icons.css';

It skips SASS and in plain CSS the url() rebasing apparently works...

cernyjakub avatar Jul 20 '22 10:07 cernyjakub

Can confirm this is still an issue regarding the latest versions. Using Vite and SASS, @import "~bootstrap-icons/font/bootstrap-icons"; which includes the SASS version, does in fact break. Workaround as mentioned, @import "~bootstrap-icons/font/bootstrap-icons.css"; does fix the issue.

tyqualters avatar Aug 15 '22 20:08 tyqualters

Any idea what the Vite Sass compiler is doing that's different than the usual Sass compilation? We're not seeing any build errors on our end.

mdo avatar Aug 28 '22 17:08 mdo

parcel.js is failing in similar way too: https://github.com/parcel-bundler/parcel/issues/6285 except that the .css workaround doesn't seem to work

nCrazed avatar Nov 18 '22 17:11 nCrazed

This should be fixed in main and will be in v1.10.4.

XhmikosR avatar Mar 25 '23 18:03 XhmikosR

I am still seeing the same erratic behavior, even after upgrading to 1.10.5

cernyjakub avatar Jun 13 '23 19:06 cernyjakub

I know this is old, so not meaning to necro, but Vite 4.x changed the default charset to UTF-8 and recommends people ensure they're using the correct Content-Type header when serving CSS, as well as having your index.html include the <meta charset="utf-8 /> tag in your <head>, which should be default for Vite users anyway.

Thread: https://github.com/vitejs/vite/issues/13676#issuecomment-1612688039

andymerskin avatar Nov 09 '23 00:11 andymerskin

This should be fixed in main and will be in v1.10.4.

I think this issue should be re-opened as the problem still persists.

CatchABus avatar Nov 20 '23 12:11 CatchABus

I'm using version 1.11.2 with vite 4.4.11 and I have tried the workaround mentioned by @cernyjakub and @tyqualters and the issue persists.

I get this error in the console:

image

And this error in the server (Django server, vite server doesn't log anything):

image

Is there any news about this bug or other workarounds?

oussama-he avatar Jan 03 '24 09:01 oussama-he

I use the workaround given by @cernyjakub and @tyqualters which is to include the plain css instead of the sass version.

I describe the same workaround in my blog How to Install Bootstrap in Laravel With Vite

This is far from ideal, I'd prefer to be able to use the sass version.

jhjvandenbroek avatar Jan 04 '24 12:01 jhjvandenbroek

@jhjvandenbroek do you use the same versions (bootstrap-icons 1.11.2 and vite 4.4.11)? The workaround doesn't work for me.

oussama-he avatar Jan 05 '24 08:01 oussama-he

No, I used:

vite 4.4.7 bootstrap-icons 1.11.1

jhjvandenbroek avatar Jan 05 '24 16:01 jhjvandenbroek