fix(compiler-sfc): support transforming asset urls with full base url. (#2477)
This commit is contained in:
@@ -121,12 +121,17 @@ export const transformAssetUrl: NodeTransform = (
|
||||
attr.value.content[0] !== '@' &&
|
||||
isRelativeUrl(attr.value.content)
|
||||
) {
|
||||
// Allow for full hostnames provided in options.base
|
||||
const base = parseUrl(options.base)
|
||||
const protocol = base.protocol || ''
|
||||
const host = base.host ? protocol + '//' + base.host : ''
|
||||
const basePath = base.path || '/'
|
||||
|
||||
// when packaged in the browser, path will be using the posix-
|
||||
// only version provided by rollup-plugin-node-builtins.
|
||||
attr.value.content = (path.posix || path).join(
|
||||
options.base,
|
||||
url.path + (url.hash || '')
|
||||
)
|
||||
attr.value.content =
|
||||
host +
|
||||
(path.posix || path).join(basePath, url.path + (url.hash || ''))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -35,5 +35,5 @@ export function parseUrl(url: string): UrlWithStringQuery {
|
||||
function parseUriParts(urlString: string): UrlWithStringQuery {
|
||||
// A TypeError is thrown if urlString is not a string
|
||||
// @see https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost
|
||||
return uriParse(isString(urlString) ? urlString : '')
|
||||
return uriParse(isString(urlString) ? urlString : '', false, true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user