Skip to content

Commit 4eb3154

Browse files
patak-devbluwy
andauthored
fix: warn when publicDir and outDir are nested (#13742)
Co-authored-by: Bjorn Lu <[email protected]>
1 parent c971f26 commit 4eb3154

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/vite/src/node/build.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,19 @@ function prepareOutDir(
753753
config.publicDir &&
754754
fs.existsSync(config.publicDir)
755755
) {
756+
if (!areSeparateFolders(outDir, config.publicDir)) {
757+
config.logger.warn(
758+
colors.yellow(
759+
`\n${colors.bold(
760+
`(!)`,
761+
)} The public directory feature may not work correctly. outDir ${colors.white(
762+
colors.dim(outDir),
763+
)} and publicDir ${colors.white(
764+
colors.dim(config.publicDir),
765+
)} are not separate folders.\n`,
766+
),
767+
)
768+
}
756769
copyDir(config.publicDir, outDir)
757770
}
758771
}
@@ -1223,3 +1236,9 @@ export function toOutputFilePathWithoutRuntime(
12231236

12241237
export const toOutputFilePathInCss = toOutputFilePathWithoutRuntime
12251238
export const toOutputFilePathInHtml = toOutputFilePathWithoutRuntime
1239+
1240+
function areSeparateFolders(a: string, b: string) {
1241+
const na = normalizePath(a)
1242+
const nb = normalizePath(b)
1243+
return na !== nb && !na.startsWith(nb + '/') && !nb.startsWith(na + '/')
1244+
}

0 commit comments

Comments
 (0)