From 11444dcee0404bae738e61b903acf37163915d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Fri, 19 Apr 2024 01:06:16 +0900 Subject: [PATCH] feat: show warning if root is in build.outDir (#16454) --- packages/vite/src/node/config.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 178e73b8137428..2b0f6d28360987 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -45,6 +45,7 @@ import { isFilePathESM, isNodeBuiltin, isObject, + isParentDirectory, mergeAlias, mergeConfig, normalizeAlias, @@ -914,6 +915,20 @@ assetFileNames isn't equal for every build.rollupOptions.output. A single patter ) } + const resolvedBuildOutDir = normalizePath( + path.resolve(resolved.root, resolved.build.outDir), + ) + if ( + isParentDirectory(resolvedBuildOutDir, resolved.root) || + resolvedBuildOutDir === resolved.root + ) { + resolved.logger.warn( + colors.yellow(` +(!) build.outDir must not be the same directory of root or a parent directory of root as this could cause Vite to overwriting source files with build outputs. +`), + ) + } + return resolved }