fix(compiler-sfc): fix skipped srcset transform when using base option
Based on implementation from #4835 due to conflicts fix #4819 close #4834, close #4835
This commit is contained in:
@@ -69,40 +69,45 @@ export const transformSrcset: NodeTransform = (
|
||||
}
|
||||
}
|
||||
|
||||
const hasQualifiedUrl = imageCandidates.some(({ url }) => {
|
||||
const shouldProcessUrl = (url: string) => {
|
||||
return (
|
||||
!isExternalUrl(url) &&
|
||||
!isDataUrl(url) &&
|
||||
(options.includeAbsolute || isRelativeUrl(url))
|
||||
)
|
||||
})
|
||||
}
|
||||
// When srcset does not contain any qualified URLs, skip transforming
|
||||
if (!hasQualifiedUrl) {
|
||||
if (!imageCandidates.some(({ url }) => shouldProcessUrl(url))) {
|
||||
return
|
||||
}
|
||||
|
||||
if (options.base) {
|
||||
const base = options.base
|
||||
const set: string[] = []
|
||||
imageCandidates.forEach(({ url, descriptor }) => {
|
||||
let needImportTransform = false
|
||||
|
||||
imageCandidates.forEach(candidate => {
|
||||
let { url, descriptor } = candidate
|
||||
descriptor = descriptor ? ` ${descriptor}` : ``
|
||||
if (isRelativeUrl(url)) {
|
||||
set.push((path.posix || path).join(base, url) + descriptor)
|
||||
if (url[0] === '.') {
|
||||
candidate.url = (path.posix || path).join(base, url)
|
||||
set.push(candidate.url + descriptor)
|
||||
} else if (shouldProcessUrl(url)) {
|
||||
needImportTransform = true
|
||||
} else {
|
||||
set.push(url + descriptor)
|
||||
}
|
||||
})
|
||||
attr.value.content = set.join(', ')
|
||||
return
|
||||
|
||||
if (!needImportTransform) {
|
||||
attr.value.content = set.join(', ')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const compoundExpression = createCompoundExpression([], attr.loc)
|
||||
imageCandidates.forEach(({ url, descriptor }, index) => {
|
||||
if (
|
||||
!isExternalUrl(url) &&
|
||||
!isDataUrl(url) &&
|
||||
(options.includeAbsolute || isRelativeUrl(url))
|
||||
) {
|
||||
if (shouldProcessUrl(url)) {
|
||||
const { path } = parseUrl(url)
|
||||
let exp: SimpleExpressionNode
|
||||
if (path) {
|
||||
|
||||
Reference in New Issue
Block a user