Skip to content

Commit

Permalink
perf: skip globbing for static path in warmup (#19107)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored Jan 2, 2025
1 parent b178c90 commit 677508b
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions packages/vite/src/node/server/warmup.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}

0 comments on commit 677508b

Please sign in to comment.