Skip to content

Commit

Permalink
fix: avoid wrong warning of explicit public paths (#4927)
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Sep 14, 2021
1 parent e687d98 commit 9e06b81
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/vite/src/node/server/middlewares/transform.ts
Expand Up @@ -114,20 +114,22 @@ export function transformMiddleware(
}
}

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(publicPath, '/')
)}.`
// check if public dir is inside root dir
const publicDir = normalizePath(server.config.publicDir)
const rootDir = normalizePath(server.config.root)
if (publicDir.startsWith(rootDir)) {
const publicPath = `${publicDir.slice(rootDir.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(publicPath, '/')
)}.`
)
)
)
}
}

if (
Expand Down

0 comments on commit 9e06b81

Please sign in to comment.