diff --git a/packages/vite/src/node/server/warmup.ts b/packages/vite/src/node/server/warmup.ts index 341d360ece5ac2..7911e0b647df07 100644 --- a/packages/vite/src/node/server/warmup.ts +++ b/packages/vite/src/node/server/warmup.ts @@ -1,7 +1,7 @@ import fs from 'node:fs/promises' import path from 'node:path' import colors from 'picocolors' -import { glob } from 'tinyglobby' +import { glob, isDynamicPattern } from 'tinyglobby' import { FS_PREFIX } from '../constants' import { normalizePath } from '../utils' import type { ViteDevServer } from '../index' @@ -72,10 +72,29 @@ function fileToUrl(file: string, root: string) { async function mapFiles(files: string[], root: string) { if (!files.length) return [] - return await glob(files, { - absolute: true, - cwd: root, - expandDirectories: false, - ignore: ['**/.git/**', '**/node_modules/**'], - }) + + const result: string[] = [] + const globs: string[] = [] + for (const file of files) { + if (isDynamicPattern(file)) { + globs.push(file) + } else { + if (path.isAbsolute(file)) { + result.push(file) + } else { + result.push(path.resolve(root, file)) + } + } + } + if (globs.length) { + result.push( + ...(await glob(globs, { + absolute: true, + cwd: root, + expandDirectories: false, + ignore: ['**/.git/**', '**/node_modules/**'], + })), + ) + } + return result }