-
Notifications
You must be signed in to change notification settings - Fork 58
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
[Feature Request] Include Icons in build instead of doing network requests #34
Comments
Hey guys! I was thinking of implementing this feature but I was wondering which approach should I take. Maybe adding a module option like |
I think it's also important for online mode, bc for instance if I have a theme switcher and click on it (switching color theme and icon) the icon disappears for a few hundred ms until the new one is downloaded. Would be nice if in online mode it would download and cache all icons right away in the background after page load is finished. You can see the effect here: https://webapicheck.com |
Any news about that? Thanks |
I found this in the Doc for building an offline bundle https://docs.iconify.design/icon-components/bundles/ |
Hi, thanks for the help. I took a look. I'm using this https://github.com/nuxt-modules/icon and figured out that this module puts the svg directly on html, so it loads offline. I saw that using capacitor and generating an apk the icon wasn't showing. So I think the problem is with capacitor and not from offline. |
@toniengelhardt I guess you could do that with plain CSS |
It says "the icons won't be loaded on initial load and an HTTP request will be made to Iconify CDN to load them" in the README though? |
I need this. It only shows |
In the end, I downloaded icons from icones.js.org and integrated them using nuxt-icons. 😅 |
@mkdirnow how is that possible? |
Seems inconvenient though... |
In fact, most of the icons in my project are individual SVG files, and only a few places use icons from icones.js.org. |
I agree with everything @madebyfabian mentioned but want to add another point. Tbh I was assuming things were bundled at build time as nowhere in the readme individual http requests are mentioned. |
I was using unplugin-icons (which bundled the icons at build time) before migrating to Nuxt. Do you foresee this to be a difficult issue to solve? |
With Unplugin icons you need to import manually the icons you use, with Nuxt icons its a string that could be any unicons icon. |
Not if you set up auto-importing |
As a user od the module I would also love to see the option to support bundled icons without having to do the request to get them. Only missing part for it to be perfect for us. |
We can create a nitro event handler to serve the icons data from either What do you think @atinux ? |
In what case would it be more performant than Iconify API @stafyniaksacha ? |
I'm currently developing a Vue application designed for offline use. I've been contemplating migrating to Nuxt due to its appealing features, such as automatic component imports and integrated UI libraries. However, I'm concerned that Nuxt may predominantly cater to applications with an online-first approach. I'm eager to hear from anyone who has experience in building offline applications using Nuxt. Specifically, I'm interested in understanding any potential drawbacks or limitations encountered during development. Does Nuxt accommodate the needs of offline applications effectively, or are there significant challenges I should be aware of? |
Currently very unfriendly for offline applications. |
We are planning to rewrite this module to avoid making network requests. As workaround, if you are using UnoCSS, you can use https://unocss.dev/presets/icons If you are using TailwindCSS, you take take a look at https://github.com/egoist/tailwindcss-icons If you are using Nuxt UI, we already support offline with UIcon component (based on TailwindCSS-Icons) |
re: "Include Icons in build instead of doing network requests" nuxt/icon#34 (comment) Signed-off-by: delano <delano@cpan.org>
I still believe there would be some of us who would benefit from bundling the icons into the build. Maybe there could be an option to opt-in? Mainly because right now (v1.2.0) if I create a SPA with It would be nice to be able to bundle the icons natively without relying on the UnoCSS or TailwindCSS workarounds. |
The main selling point of using Nuxt Icons is the dynamic bits, which support rendering icons that you retrieved at runtime (dynamic content, user content, etc.). Other solutions like Because the focus is fully dynamic, meaning it would be hard for Nuxt Icon to pre-bundle the icons at build time. For example, to know the usage of your icons, the module would need to scan every file in your project to detect usage statically like this: <template>
<Icon name="carbon:sun" />
</template> Where the cases like: <script setup>
const props = defineProps({
icon: String
})
</script>
<template>
<Icon :name="icon" />
</template> It won't be possible to know what's the value of the props passed in at build time. (any many more edge cases like this). That said, I would still love to improve the DX with this, but in order to perform good static analysis result, we would need to:
I would need to have some examples of your project usage to know what would be the best way to support that. Please share your project or a minified version below and tell your usage/expectation. So we could come up with a better design that works for the majority of the users. Thanks |
@antfu it might not be ideal, but if the scanning is too complex, maybe there could be a Defining aliases for all icons is anyway good practice IMO, it makes the project more maintainable. |
You are right @antfu. I see your point in how this introduces complexity beyond what I would know how to do. I won't say this is a deal breaker, it's just a UX/DX improvement. It is definitely so nice to only write the icon name and magically have it appear. Unfortunately, as soon as the client is hydrated and SPA takes control, rendering icons that weren't at the initial page load last a tiny bit to appear, which feels weird but it's not critical. If this feature is at all possible, but requires defining a fixed pattern to write the names of icons (such as TailwindCSS Icons with I tried Most of the projects I build are SPA's on the client side, since they are admin dashboards or management platforms. I don't use SSR as much. But even with SSR, once hydration happens, I have the same issue. Here's a video on what I mean (uses 3G network throttling to make the icon loading time more visible) Arc.mp4 |
Please upgrade to v1.5.0 and give it a try with #243, feedback are greatly welcome (please create new issues). |
Hi @antfu I was even surprised to find out that dynamic icons still get loaded without any extra setup. For example: <script setup lang="ts">
const props = defineProps<{ type: string }>();
export function getMimeTypeIcon(type: string) {
if (!type) return 'i-heroicons-question-mark-circle';
if (type.startsWith('image')) return 'i-heroicons-camera';
if (type.startsWith('video')) return 'i-heroicons-video-camera';
if (type.startsWith('audio')) return 'i-heroicons-musical-note';
if (type.endsWith('csv')) return 'i-heroicons-table-cells';
return 'i-heroicons-document';
}
</script>
<template>
<Icon :name="`${getMimeTypeIcon(type)}-16-solid`" />
</template> (I know that example is not ideal, but I wrote it just out of curiosity to test string templates and it worked) Even though they won't get bundled since it's nearly impossible to scan for those cases, the fact that I didn't have to set anything up to make that icon dynamic is just magic. Thank you very much! I will keep trying it with more use cases and let you know if anything doesn't work. |
The clientBundle/scan feature is great 👍 However, whenever an icon is missed, my app ( |
@some-user123 Avoiding to render if not included in the bundle is not possible and I don't believe it's part of what this module is trying to achieve. I recommend you use Hope that helps! |
Hey there, thanks so much for this module! It's absolutely great and easy to use.
I noticed something though, where I couldn't find a config for. In Production, the icons are loaded over the network via
https://api.iconify.design/ri.json?icons=icon-name
. This can cause several issues, such as:Maybe I'm understanding wrong and the Module perfectly works without connecting to this API, but I think it would be great to have an option to store all used icons locally on build and request them from a local server endpoint.
The text was updated successfully, but these errors were encountered: