restructured and simplified favicon
This commit is contained in:
parent
8986f6533e
commit
13fdf05a91
18 changed files with 117 additions and 60 deletions
30
image-plugin.ts
Normal file
30
image-plugin.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { plugin, type BunPlugin } from "bun";
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
const imageLoaderPlugin: BunPlugin = {
|
||||
name: "image-loader",
|
||||
setup(builder) {
|
||||
builder.onLoad({ filter: /\.(png|jpg|jpeg|webp)/ }, async ({ path }) => {
|
||||
try {
|
||||
const file = Bun.file(path);
|
||||
const bytes = await file.bytes();
|
||||
return {
|
||||
exports: { default: bytes },
|
||||
loader: "object",
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
if (err instanceof Error) {
|
||||
throw new Error(`Failed to load file: ${err.message}`);
|
||||
} else if (typeof err === 'string') {
|
||||
throw new Error(`Failed to load file: ${err}`);
|
||||
}
|
||||
throw new Error("Failed to load file");
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
plugin(imageLoaderPlugin);
|
||||
|
||||
export default imageLoaderPlugin;
|
Loading…
Add table
Add a link
Reference in a new issue