Skip to content

Commit

Permalink
fix: unexpected file request with custom publicDir, fix vitejs#4629 (v…
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 authored and aleclarson committed Nov 8, 2021
1 parent 60af5f5 commit 6091ba8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/vite/src/node/server/middlewares/transform.ts
Expand Up @@ -114,13 +114,17 @@ export function transformMiddleware(
}
}

// warn explicit /public/ paths
if (url.startsWith('/public/')) {
const publicPath =
normalizePath(server.config.publicDir).slice(
server.config.root.length
) + '/'
// warn explicit public paths
if (url.startsWith(publicPath)) {
logger.warn(
chalk.yellow(
`files in the public directory are served at the root path.\n` +
`Instead of ${chalk.cyan(url)}, use ${chalk.cyan(
url.replace(/^\/public\//, '/')
url.replace(publicPath, '/')
)}.`
)
)
Expand Down

0 comments on commit 6091ba8

Please sign in to comment.