feat: allow using IconifyJSON as custom collection#366
Merged
Conversation
4f99b19 to
688f174
Compare
Aareksio
commented
Mar 9, 2025
|
|
||
| function loadCollection(prefix: string) { | ||
| if (customCollectionNames.has(prefix)) { | ||
| const collection = customCollections.find(c => c.prefix === prefix) |
Contributor
Author
There was a problem hiding this comment.
.find should be alright here. We enter this path only once per custom collection. Optimizing lookup seems like an overkill for the sensible length of customCollections.
| if (customCollectionNames.has(prefix)) { | ||
| const collection = customCollections.find(c => c.prefix === prefix) | ||
| if (collection) { | ||
| return Promise.resolve(collection) |
Contributor
Author
There was a problem hiding this comment.
Using the Promise.resolve here to keep the return type Promise<IconifyJSON | undefined> and play nicely with existing logic of iconifyCollectionMap.
Comment on lines
+246
to
+249
| const data = getIconData(collection, name) | ||
| if (data) { | ||
| addIcon(collection.prefix, name, data) | ||
| } |
Contributor
Author
There was a problem hiding this comment.
This is the change which properly merges icon settings with collection settings. Previously, each SVG icon had all the metadata (mostly width and height) embedded in its declaration. With IconifyJSON, it is common to keep common values on the collection level.
// SVG collection as loaded from `dir`
{
prefix: 'svg',
icons: {
'nuxt-v2': { body: '...', height: 512, width: 512 },
'nuxt-v3': { body: '...', height: 512, width: 512 },
}
}
// _Optimized_ IconifyJSON for premium icon set
{
prefix: 'optimized',
icons: {
'nuxt-v2': { body: '...' },
'nuxt-v3': { body: '...' },
},
height: 512,
width: 512,
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
N/A
❓ Type of change
📚 Description
Motivation
Using non-public
IconifyJSONcollections is common when working with premium icon sets or aiming for build optimizations by avoiding repetitive SVG parsing on each build.Current issue
Currently, custom icon collections can be included using the
serverBundle.collectionsoption. However, this approach has significant drawbacks since it disables importantnuxt-iconfeatures such as server bundle auto-detection and client-side bundling.Proposed solution
This PR updates
nuxt-iconto recognize and properly handleIconifyJSONcollections as custom collections. This ensures seamless integration, preserves all existing features (including auto-detection and client-side bundling), and provides a more robust solution for users who want to leverage private or optimized icon sets.Major changes
customCollectionsnow supports direct use ofIconifyJSONobjectsclientBundle.scantotruenow also includes scanning for custom icon collectionsMinor fixes
In the playground, when
includeCustomCollections: trueis not set,nuxt-v3icon without a prefix breaks. I suspect it may have something to do withuseResolvedName, as a network call tonuxt.json?icon=v3can be spotted when opening the playground.This PR causes minimal conflicts with #360. I am willing to resolve them if needed.