网页 综合 更新时间 2026-11-16 04:29:52

Server & Client Bundle · @nuxt/icon · Nuxt Modules

自动蜘蛛 nuxt.com 正文约 4104 字
Server & Client Bundle · @nuxt/icon · Nuxt Modules
Since @nuxt/icon v1.0, we have introduced the server bundle concept to serve the icons from Nuxt server endpoints. This keeps the client bundle lean and able to load icons on-demand, while having all the dynamic features to use icons that might not be known at build time.
This mode will bundle the icon collections you have installed locally (like @iconify-json/*), into your server bundle as dynamic chunks. The collection data will be loaded on-demand, only when your client request icons from that collection.
Introduced in @nuxt/icon v1.2, you can now use the remote server bundle to serve the icons from a remote CDN.
Or you can specify the remote provider:
Which will make server requests to https://cdn.jsdelivr.net/npm/@iconify-json/ph/icons.json to fetch the icons at runtime, instead of bundling them with your server.
Under the hood, instead of bundling the collection into your server:
it will now use something like this, where the collections are not inlined:
This would be useful when server bundle size is a concern, like in serverless or worker environments.
This is the default option, where the module picks between local and remote based on your deployment target. It uses remote when you build (not in development) for an edge or worker target, that is a Nitro preset, NITRO_PRESET or SERVER_PRESET containing edge, cloudflare or worker (like vercel-edge or cloudflare-module), and local otherwise.
By default, Nitro will bundle the icon collections you have installed locally (like @iconify-json/*), into your server bundle as dynamic chunks. When you have a large number of icons, this might make your bundling process slow and memory-intensive. You can change to externalize the icons JSON files by setting icon.serverBundle.externalizeIconsJson to true.
Note that this will require your production Node.js server to be able to import JSON files (Note that as in Node.js v22, JSON modules are still an experimental feature). In the final build, it will contain statements like () => import('@iconify-json/ph/icons.json', { with: { type: 'json' } }).
Also note that in some serverless environments, like Cloudflare Workers, where they don't have dynamic imports, they will always be inlined regardless of this option.
This option will be ignored when icon.serverBundle.remote is enabled.
If you want to disable the server bundle completely, you can set icon.serverBundle to false and provider to iconify
This will make requests to Iconify API every time the client requests an icon. We do not recommend doing so unless the other options are not feasible.
provider can also be set separately for SSR and for the browser.
For icons that you know you are going to use frequently, you can bundle them with your client bundle to avoid network requests.
If you want icons to be available on first render, use the client bundle as the prefetch mechanism:
You can also enable static scanning to pre-bundle icons referenced literally in your source files:
If you want to disable runtime icon fetching entirely, see Disabling Runtime Fetching for the provider: 'none' + client bundle pattern.
includeCustomCollections will include all the custom collections you have defined in icon.customCollections in the client bundle. It's disabled by default when both sides of provider use server, and enabled otherwise (e.g. when ssr: false is set).
When scan is enabled, the module will scan all the components in your project and include the icons used in the client bundle. This would significantly reduce the number of network requests needed for statically known icons, but might also increase the client bundle size depending on the number of icons used in your project.
You can also fine-tune tine scanning targets like:
Scanning is relying on static analysis, which means only literal usages will be detected. Avoid constructing the icon name dynamically whenever possible.
Every option of the icon key in your Nuxt config.
Change stroke width, colors and more at render time.
Stay updated on new releases and features, guides, and community updates.
Copyright © 2016-2026 Nuxt - MIT License
访问原文 返回搜索 https://nuxt.com/modules/icon/bundles
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。