diff --git a/.changeset/happy-phones-accept.md b/.changeset/happy-phones-accept.md new file mode 100644 index 0000000..70ed58f --- /dev/null +++ b/.changeset/happy-phones-accept.md @@ -0,0 +1,5 @@ +--- +'vite-plugin-lqip': patch +--- + +fixed errors thrown by the fileURLToPath method (#6). diff --git a/src/index.ts b/src/index.ts index f707007..5811eac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,7 @@ import mime from 'mime'; import path from 'node:path'; -import { fileURLToPath } from 'node:url'; import sharp from 'sharp'; -import type { Plugin, UserConfig } from 'vite'; +import type { Plugin } from 'vite'; export interface LQIPPluginOptions { sharp?: { @@ -22,13 +21,9 @@ export interface LQIPPluginOptions { } export default function vitePluginLqip(options?: LQIPPluginOptions): Plugin { - let viteConfig: UserConfig = {} as unknown as UserConfig; return { name: 'vite-plugin-lqip', enforce: 'pre', - configResolved(cfg) { - viteConfig = cfg as unknown as UserConfig; - }, async load(id) { const [base, search] = id.split('?'); if (!search) { @@ -39,7 +34,7 @@ export default function vitePluginLqip(options?: LQIPPluginOptions): Plugin { return null; } - const img = sharp(fileURLToPath(new URL(base!, `file://${viteConfig.root}/`))); + const img = sharp(base); const metadata = await img.metadata(); const output = await img .toFormat('webp', {