Skip to content

Commit

Permalink
fix: warn when publicDir and outDir are nested (#13742)
Browse files Browse the repository at this point in the history
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
  • Loading branch information
patak-dev and bluwy committed Jul 17, 2023
1 parent c971f26 commit 4eb3154
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/vite/src/node/build.ts
Expand Up @@ -753,6 +753,19 @@ function prepareOutDir(
config.publicDir &&
fs.existsSync(config.publicDir)
) {
if (!areSeparateFolders(outDir, config.publicDir)) {
config.logger.warn(
colors.yellow(
`\n${colors.bold(
`(!)`,
)} The public directory feature may not work correctly. outDir ${colors.white(
colors.dim(outDir),
)} and publicDir ${colors.white(
colors.dim(config.publicDir),
)} are not separate folders.\n`,
),
)
}
copyDir(config.publicDir, outDir)
}
}
Expand Down Expand Up @@ -1223,3 +1236,9 @@ export function toOutputFilePathWithoutRuntime(

export const toOutputFilePathInCss = toOutputFilePathWithoutRuntime
export const toOutputFilePathInHtml = toOutputFilePathWithoutRuntime

function areSeparateFolders(a: string, b: string) {
const na = normalizePath(a)
const nb = normalizePath(b)
return na !== nb && !na.startsWith(nb + '/') && !nb.startsWith(na + '/')
}

0 comments on commit 4eb3154

Please sign in to comment.