From 51536f9641057fb456ff6454370e232cd353bb18 Mon Sep 17 00:00:00 2001 From: DerZade Date: Sat, 8 Jun 2024 21:32:12 +0200 Subject: [PATCH] fix: :bug: fix dev server on windows --- src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 16f39ab..cc9f33a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import { createFilter, type Plugin } from 'vite'; import { ESLiteral, toESString } from './utils/toESString'; import { readFile } from 'node:fs/promises'; -import { parse } from 'node:path'; +import { parse, basename } from 'node:path'; import sharp from 'sharp'; import mime from 'mime'; @@ -95,10 +95,12 @@ export default function srcsetPlugin(options: SrcsetPluginConfig = []): Plugin { const config = findConfig(idWithoutParams); + const importPath = './' + basename(idWithoutParams); + if (viteCommand === 'serve') { // we just serve the image during dev server operation return { - code: `import imgUrl from '${idWithoutParams}?url'; + code: `import imgUrl from '${importPath}?url'; export default ${toESString({ sources: [