Skip to content

Commit 61d5da6

Browse files
authoredDec 26, 2024··
Fix icon reloading logic to only trigger for relevant file changes (#258)
* fix: icon reloading issue * chore: add changeset
1 parent 60ea42f commit 61d5da6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

‎.changeset/twelve-students-remain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"astro-icon": patch
3+
---
4+
5+
Fix icon reloading logic to only trigger for relevant file changes

‎packages/core/src/vite-plugin-astro-icon.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
import loadLocalCollection from "./loaders/loadLocalCollection.js";
1010
import loadIconifyCollections from "./loaders/loadIconifyCollections.js";
1111
import { createHash } from "node:crypto";
12+
import Path from 'node:path'
1213

1314
interface PluginContext extends Pick<AstroConfig, "root" | "output"> {
1415
logger: AstroIntegrationLogger;
@@ -49,7 +50,12 @@ export function createPlugin(
4950
},
5051
configureServer({ watcher, moduleGraph }) {
5152
watcher.add(`${iconDir}/**/*.svg`);
52-
watcher.on("change", async () => {
53+
watcher.on("all", async (_, filepath: string) => {
54+
const parsedPath = Path.parse(filepath)
55+
const resolvedIconDir = Path.resolve(root.pathname, iconDir)
56+
const isSvgFileInIconDir = parsedPath.dir.startsWith(resolvedIconDir) && parsedPath.ext === ".svg";
57+
const isAstroConfig = parsedPath.name === "astro.config";
58+
if (!isSvgFileInIconDir && !isAstroConfig) return;
5359
console.log(`Local icons changed, reloading`);
5460
try {
5561
if (!collections) {

0 commit comments

Comments
 (0)