Skip to content

Commit b423387

Browse files
committed
chore(icons): move icons from public/ to icons/, guard chrome.runtime
- icons/ now lives at repo root (not public/) so CRXJS can copy them directly into dist/icons/ without Vite's publicDir interfering - vite.config.ts: set publicDir: false; remove manual rollupOptions input (CRXJS handles all entry points via manifest) - scripts/gen-icons.mjs: update output path public/icons/ → icons/ - HacklmIcon.tsx: guard chrome.runtime.getURL with typeof check so the component works in Storybook / non-extension environments
1 parent b03bdad commit b423387

6 files changed

Lines changed: 8 additions & 9 deletions

File tree

scripts/gen-icons.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const root = resolve(__dir, "..");
1616
const svgBuf = readFileSync(resolve(root, "hacklm.svg"));
1717

1818
for (const size of [16, 48, 128]) {
19-
const outPath = resolve(root, "public", "icons", `icon${size}.png`);
19+
const outPath = resolve(root, "icons", `icon${size}.png`);
2020
await sharp(svgBuf)
2121
.resize(size, size, { fit: "contain", background: { r: 0, g: 0, b: 0, alpha: 0 } })
2222
.png()

src/components/HacklmIcon.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88

99
import React from "react";
1010

11-
const iconUrl = (px: 16 | 48 | 128) =>
12-
chrome.runtime.getURL(`icons/icon${px}.png`);
11+
const iconUrl = (px: 16 | 48 | 128) => {
12+
if (typeof chrome !== "undefined" && chrome.runtime?.getURL) {
13+
return chrome.runtime.getURL(`icons/icon${px}.png`);
14+
}
15+
return `/icons/icon${px}.png`;
16+
};
1317

1418
function bestSize(size: number): 16 | 48 | 128 {
1519
if (size <= 16) return 16;

vite.config.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function fixServiceWorkerLoader(): Plugin {
3636
};
3737
}
3838
export default defineConfig({
39+
publicDir: false,
3940
plugins: [react(), tailwindcss(), crx({
4041
manifest
4142
}), fixServiceWorkerLoader()],
@@ -54,11 +55,5 @@ export default defineConfig({
5455
},
5556
build: {
5657
outDir: "dist",
57-
rollupOptions: {
58-
input: {
59-
options: "src/options/index.html",
60-
popup: "src/popup/index.html"
61-
}
62-
}
6358
}
6459
});

0 commit comments

Comments
 (0)