Skip to content

Commit 11444dc

Browse files
authored
feat: show warning if root is in build.outDir (#16454)
1 parent 721f94d commit 11444dc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/vite/src/node/config.ts

+15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
isFilePathESM,
4646
isNodeBuiltin,
4747
isObject,
48+
isParentDirectory,
4849
mergeAlias,
4950
mergeConfig,
5051
normalizeAlias,
@@ -914,6 +915,20 @@ assetFileNames isn't equal for every build.rollupOptions.output. A single patter
914915
)
915916
}
916917

918+
const resolvedBuildOutDir = normalizePath(
919+
path.resolve(resolved.root, resolved.build.outDir),
920+
)
921+
if (
922+
isParentDirectory(resolvedBuildOutDir, resolved.root) ||
923+
resolvedBuildOutDir === resolved.root
924+
) {
925+
resolved.logger.warn(
926+
colors.yellow(`
927+
(!) 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.
928+
`),
929+
)
930+
}
931+
917932
return resolved
918933
}
919934

0 commit comments

Comments
 (0)