Skip to content

Commit

Permalink
Output relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
zepfietje committed Aug 14, 2024
1 parent 2da03b2 commit cc82dc3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { basename, extname } from 'node:path'
import { basename, extname, parse, relative } from 'node:path'
import { statSync, mkdirSync, createReadStream } from 'node:fs'
import { writeFile, readFile, opendir, stat, rm } from 'node:fs/promises'
import type { Plugin, ResolvedConfig } from 'vite'
Expand Down Expand Up @@ -168,8 +168,11 @@ export function imagetools(userOptions: Partial<VitePluginOptions> = {}): Plugin
} else if (viteConfig.command === 'serve') {
metadata.src = (viteConfig?.server?.origin ?? '') + basePath + id
} else {
const parsedPath = parse(pathname);
const relativeDir = relative(viteConfig.root, parsedPath.dir);

const fileHandle = this.emitFile({
name: basename(pathname, extname(pathname)) + `.${metadata.format}`,
name: `${relativeDir}/${parsedPath.name}.${metadata.format}`,
source: image ? await image.toBuffer() : await readFile(`${cacheOptions.dir}/${id}`),
type: 'asset'
})
Expand Down

0 comments on commit cc82dc3

Please sign in to comment.