From f6197ca7220b18cecca1ce79b2ac53912fbe9ff6 Mon Sep 17 00:00:00 2001 From: Daniel Knibbe Date: Mon, 8 Jul 2024 21:08:04 +0200 Subject: [PATCH 1/2] Fix url concatenation for dev mode with origin set in server options --- .changeset/new-otters-turn.md | 5 +++++ packages/vite/src/index.ts | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 .changeset/new-otters-turn.md diff --git a/.changeset/new-otters-turn.md b/.changeset/new-otters-turn.md new file mode 100644 index 00000000..12089894 --- /dev/null +++ b/.changeset/new-otters-turn.md @@ -0,0 +1,5 @@ +--- +'vite-imagetools': patch +--- + +Fixed url concatenation for dev mode with origin set in server options. diff --git a/packages/vite/src/index.ts b/packages/vite/src/index.ts index f033f115..767369f2 100644 --- a/packages/vite/src/index.ts +++ b/packages/vite/src/index.ts @@ -1,5 +1,4 @@ import { basename, extname } from 'node:path' -import { join } from 'node:path/posix' import { statSync, mkdirSync, createReadStream } from 'node:fs' import { writeFile, readFile, opendir, stat, rm } from 'node:fs/promises' import type { Plugin, ResolvedConfig } from 'vite' @@ -167,7 +166,7 @@ export function imagetools(userOptions: Partial = {}): Plugin : await readFile(`${cacheOptions.dir}/${id}`) ).toString('base64')}` } else if (viteConfig.command === 'serve') { - metadata.src = join(viteConfig?.server?.origin ?? '', basePath) + id + metadata.src = (viteConfig?.server?.origin ?? '') + basePath + id } else { const fileHandle = this.emitFile({ name: basename(pathname, extname(pathname)) + `.${metadata.format}`, From ead219f3c557f706b957c0716746cc67e0312fca Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 10 Jul 2024 09:18:10 -0700 Subject: [PATCH 2/2] Update .changeset/new-otters-turn.md --- .changeset/new-otters-turn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/new-otters-turn.md b/.changeset/new-otters-turn.md index 12089894..65a1e392 100644 --- a/.changeset/new-otters-turn.md +++ b/.changeset/new-otters-turn.md @@ -2,4 +2,4 @@ 'vite-imagetools': patch --- -Fixed url concatenation for dev mode with origin set in server options. +fix: correct URL concatenation in dev mode when origin set in server options