Skip to content
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

[Bug]: Vite custom font scanning all available font files including node_modules #74

Open
chunlampang opened this issue Sep 13, 2024 · 2 comments

Comments

@chunlampang
Copy link
Contributor

chunlampang commented Sep 13, 2024

Describe the feature

Since there are some font files (e.g. icon font) already handled by other plugin, unplugin-fonts is no need to inject those files. It just need to inject the configurated fonts instead of inject every available font files inside the build.
It is suggested that adding an option to disable control custom font.

Update - it is a bug

Vite custom font scanning all available font files including node_modules file on build

@chunlampang
Copy link
Contributor Author

Are the following code repeated?

tags.push({
tag: 'link',
injectTo: options?.custom?.injectTo ?? 'head-prepend',
attrs: {
rel: options?.custom?.prefetch ? 'prefetch' : 'preload',
as: 'font',
type: `font/${ext.replace('.', '')}`,
href: join(base, file),
crossorigin: 'anonymous',
},
})

unplugin-fonts/src/index.ts

Lines 126 to 136 in a7e66d5

tags.push({
tag: 'link',
injectTo: options.custom?.injectTo ?? 'head-prepend',
attrs: {
rel: options.custom?.prefetch ? 'prefetch' : 'preload',
as: 'font',
type: `font/${ext.replace('.', '')}`,
href: join(base, file),
crossorigin: 'anonymous',
},
})

@chunlampang chunlampang changed the title [Feature]: Vite add option to disable scanning all available font files and inject to the html [Bug]: Vite custom font scanning all available font files including node_modules Sep 27, 2024
@segevfiner
Copy link

I'm hitting this as well, and this results in console warnings in my app, due to adding preload directives for fonts that are only used in async chunks that are not loaded with the app. This happens because the current code generates preload directives for all fonts in the bundle rather than only fonts included via custom which is undesirable IMHO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants