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(html): dont pretransform public scripts #12650

Merged
merged 3 commits into from
Mar 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/vite/src/node/server/middlewares/indexHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
unwrapId,
wrapId,
} from '../../utils'
import { checkPublicFile } from '../../plugins/asset'

interface AssetNode {
start: number
Expand Down Expand Up @@ -80,7 +81,6 @@ function getHtmlFilename(url: string, server: ViteDevServer) {
}
}

const startsWithSingleSlashRE = /^\/(?!\/)/
const processNodeUrl = (
attr: Token.Attribute,
sourceCodeLocation: Token.Location,
Expand All @@ -99,11 +99,13 @@ const processNodeUrl = (
}
}
const devBase = config.base
if (startsWithSingleSlashRE.test(url)) {
if (url[0] === '/' && url[1] !== '/') {
// prefix with base (dev only, base is never relative)
const fullUrl = path.posix.join(devBase, url)
overwriteAttrValue(s, sourceCodeLocation, fullUrl)
if (server) preTransformRequest(server, fullUrl, devBase)
if (server && !checkPublicFile(url, config)) {
preTransformRequest(server, fullUrl, devBase)
}
} else if (
url[0] === '.' &&
originalUrl &&
Expand All @@ -113,7 +115,9 @@ const processNodeUrl = (
// prefix with base (dev only, base is never relative)
const replacer = (url: string) => {
const fullUrl = path.posix.join(devBase, url)
if (server) preTransformRequest(server, fullUrl, devBase)
if (server && !checkPublicFile(url, config)) {
preTransformRequest(server, fullUrl, devBase)
}
return fullUrl
}

Expand Down