diff --git a/bunfig.toml b/bunfig.toml index 676dd9e..9fb5867 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -1,3 +1,5 @@ +preload = ["./image-plugin.ts"] + [install.scopes] "@jsr" = "https://npm.jsr.io" diff --git a/image-plugin.ts b/image-plugin.ts new file mode 100644 index 0000000..9f08d92 --- /dev/null +++ b/image-plugin.ts @@ -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; diff --git a/src/client/components/login.svelte b/src/client/components/login.svelte index 9cd40c1..a1e49b2 100644 --- a/src/client/components/login.svelte +++ b/src/client/components/login.svelte @@ -1,9 +1,11 @@ - - -
- - -