-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to load a font with Vue Web Component Wrapper #54
Comments
If You want to use pure CSS use |
I have changed the example and I have added a .less file with font face definitions.
And this is the file fonts.less
The fonts aren't loaded by browser: I have read that font-face is not working with shadow-root. Thanks!! |
Take a look on what is generated, if path is correct etc. |
So it's working correctly, right? Did You try using it? Maybe Chrome won't download it untill used? |
But why is not being used? I can't understand it. The style is loaded inside shadow-root however it seems that the font-face rule is not being processed. I think load a font inside a web component should be very common.. so I don't think that I'm the first who has this problem. Can be this a bug of the wrapper or is related to the web components maybe? PS: If I load the styles in doing something like it works correctly.
|
I mean - did you style some div/p etc. with font-family you've imported? If not why Chrome should download this font if it's not used? |
Yes off course.. the code is in the first comment. The styles are:
and the template:
|
Please prepare GitHub or CodeSandbox repo. Regards! |
Finally I have solved it creating a component called for example 'FontsLoader.vue' that loads the fonts style
and then when its mounted() loop over the shadowRoot child nodes to find the node with @font-face declarations and append a new child in the head with the node content. |
same issue~ |
Any solution for this? |
My fonts load fine in the dev version, but they don't work in build. |
@serbemas could you please share your solution code? this is what I did following your spec
given that
and after doing that, I was able to use fonts in web component.
Important note! I did include |
I wish @vitejs/vite-plugin-vue could extract Or if somebody can write a custom |
I'm working in a new project using Vue CLI 3 and I'm having an issue when I try to load a font in a web component.
I have prepared this basic example.
And this is the code generated running npm serve:
As you can see in the image above, it generates an <style> tag with this content:
<style type="text/css">@import url(https://fonts.googleapis.com/css?family=Montserrat&display=swap);</style>
How can I solve this?
The text was updated successfully, but these errors were encountered: