Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: warn when publicDir and outDir are nested #13742

Merged
merged 6 commits into from Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 + '/')
}