@@ -106,6 +106,54 @@ export interface Options {
106106 * @deprecated no longer needed
107107 */
108108 iconSource ?: 'legacy' | 'modern' | 'auto'
109+
110+ /**
111+ * HMR helper to resolve the icon id from local file SVG changes.
112+ *
113+ * **NOTE:** works only with Vite.
114+ *
115+ * Since there is no way to correlate the icon name with the local file SVG, we need a helper to invalidate the
116+ * corresponding icon module.
117+ *
118+ * For example, we can have a custom collection using `readFile`, we cannot resolve `~icons/inline/async`
119+ * when `<project-root>/assets/giftbox.svg` changes:
120+ * ```ts
121+ * customCollections: {
122+ * inline: {
123+ * async: () => fs.readFile('assets/giftbox.svg', 'utf-8')
124+ * }
125+ * }
126+ * ```
127+ *
128+ * To resolve the icon in the previous example you will need to add:
129+ * ```ts
130+ * hmrResolver(file) => file.endsWidth('assets/giftbox.svg') ? 'inline/async' : undefined
131+ * ```
132+ *
133+ * The `normalizedSVGIconName` is the SVG basename without the extension converted to kebab-case, will help you when using `FileSystemIconLoader`:
134+ * ```ts
135+ * customCollections: {
136+ * custom: FileSystemIconLoader('assets/custom-a')
137+ * }
138+ * ```
139+ *
140+ * then, to resolve the icons from the `assets/custom-a` folder you only need to add the corresponding collection name:
141+ * To resolve the icon in the previous example you will need to add:
142+ * ```ts
143+ * hmrResolver(file, folderName, normalizedSVGIconName) {
144+ * if (folderName.endsWith('assets/custom-a') {
145+ * return `custom/${normalizedSVGIconName}`
146+ * }
147+ * }
148+ * ```
149+ *
150+ * @param file The file path received from the Vite's [handleHotUpdate](https://vite.dev/guide/api-plugin.html#handlehotupdate) hook.
151+ * @param folderName The normalized folder containing the file.
152+ * @param normalizedSVGIconName The normalized SVG name (basename without extension and the path).
153+ * @return The icon collection and name to invalidate (<collection>/<icon>).
154+ * @see https://vitejs.dev/guide/api-plugin.html#handlehotupdate
155+ */
156+ hmrResolver ?: ( file : string , folderName : string , normalizedSVGIconName : string ) => Awaitable < string | string [ ] | undefined >
109157}
110158
111- export type ResolvedOptions = Omit < Required < Options > , 'iconSource' | 'transform' > & Pick < Options , 'transform' >
159+ export type ResolvedOptions = Omit < Required < Options > , 'iconSource' | 'transform' | 'hmrResolver' > & Pick < Options , 'transform' | 'hmrResolver '>
0 commit comments