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: allow full hostnames in asset url base, fix #12731 #12732

Merged
merged 2 commits into from Aug 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/compiler-sfc/src/templateCompilerModules/utils.ts
Expand Up @@ -24,10 +24,15 @@ export function urlToRequire(
// does not apply to absolute urls or urls that start with `@`
// since they are aliases
if (firstChar === '.' || firstChar === '~') {
// Allow for full hostnames provided in options.base
const base = parseUriParts(transformAssetUrlsOption.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.
return `"${(path.posix || path).join(
transformAssetUrlsOption.base,
return `"${host}${(path.posix || path).join(
basePath,
uriParts.path + (uriParts.hash || '')
)}"`
}
Expand Down Expand Up @@ -64,7 +69,7 @@ function parseUriParts(urlString: string): UrlWithStringQuery {
// @see https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost
if ('string' === typeof urlString) {
// check is an uri
return uriParse(urlString) // take apart the uri
return uriParse(urlString, false, true) // take apart the uri
}
}
return returnValue
Expand Down