Skip to content

Commit

Permalink
feat: show warning if root is in build.outDir (#16454)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Apr 18, 2024
1 parent 721f94d commit 11444dc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
isFilePathESM,
isNodeBuiltin,
isObject,
isParentDirectory,
mergeAlias,
mergeConfig,
normalizeAlias,
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 11444dc

Please sign in to comment.