diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 36a8bdc7be810c..496664baf8897a 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -630,7 +630,9 @@ export function runOptimizeDeps( stringifyDepsOptimizerMetadata(metadata, depsCacheDir), ) - debug(`deps bundled in ${(performance.now() - start).toFixed(2)}ms`) + debug( + `Dependencies bundled in ${(performance.now() - start).toFixed(2)}ms`, + ) return createProcessingResult() }) diff --git a/packages/vite/src/node/optimizer/optimizer.ts b/packages/vite/src/node/optimizer/optimizer.ts index 9e016310709f8c..5c159f3b6d9d8a 100644 --- a/packages/vite/src/node/optimizer/optimizer.ts +++ b/packages/vite/src/node/optimizer/optimizer.ts @@ -221,16 +221,6 @@ async function createDepsOptimizer( const deps = await discover.result discover = undefined - debug( - colors.green( - Object.keys(deps).length > 0 - ? `dependencies found by scanner: ${depsLogString( - Object.keys(deps), - )}` - : `no dependencies found by scanner`, - ), - ) - // Add these dependencies to the discovered list, as these are currently // used by the preAliasPlugin to support aliased and optimized deps. // This is also used by the CJS externalization heuristics in legacy mode diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index 32f9b2b1f4b979..37e5c52b07950c 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -33,6 +33,7 @@ import { transformGlobImport } from '../plugins/importMetaGlob' type ResolveIdOptions = Parameters[2] +const isDebug = process.env.DEBUG const debug = createDebugger('vite:deps') const htmlTypesRE = /\.(html|vue|svelte|astro|imba)$/ @@ -83,7 +84,11 @@ export function scanImports(config: ResolvedConfig): { } if (scanContext.cancelled) return - debug(`Crawling dependencies using entries:\n ${entries.join('\n ')}`) + debug( + `Crawling dependencies using entries: ${entries + .map((entry) => `\n ${colors.dim(entry)}`) + .join('')}`, + ) return prepareEsbuildScanner(config, entries, deps, missing, scanContext) }) @@ -135,10 +140,15 @@ export function scanImports(config: ResolvedConfig): { throw e }) .finally(() => { - debug( - `Scan completed in ${(performance.now() - start).toFixed(2)}ms:`, - deps, - ) + if (isDebug) { + const duration = (performance.now() - start).toFixed(2) + const depsStr = + Object.keys(orderedDependencies(deps)) + .sort() + .map((id) => `\n ${colors.cyan(id)} -> ${colors.dim(deps[id])}`) + .join('') || colors.dim('no dependencies found') + debug(`Scan completed in ${duration}ms: ${depsStr}`) + } }) return {