Skip to content

Commit 5c742eb

Browse files
authored
fix(compiler-sfc): allow full hostnames in asset url base (#12732)
fix #12731
1 parent 00458cd commit 5c742eb

File tree

1 file changed

+8
-3
lines changed
  • packages/compiler-sfc/src/templateCompilerModules

1 file changed

+8
-3
lines changed

packages/compiler-sfc/src/templateCompilerModules/utils.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ export function urlToRequire(
2424
// does not apply to absolute urls or urls that start with `@`
2525
// since they are aliases
2626
if (firstChar === '.' || firstChar === '~') {
27+
// Allow for full hostnames provided in options.base
28+
const base = parseUriParts(transformAssetUrlsOption.base)
29+
const protocol = base.protocol || ''
30+
const host = base.host ? protocol + '//' + base.host : ''
31+
const basePath = base.path || '/'
2732
// when packaged in the browser, path will be using the posix-
2833
// only version provided by rollup-plugin-node-builtins.
29-
return `"${(path.posix || path).join(
30-
transformAssetUrlsOption.base,
34+
return `"${host}${(path.posix || path).join(
35+
basePath,
3136
uriParts.path + (uriParts.hash || '')
3237
)}"`
3338
}
@@ -64,7 +69,7 @@ function parseUriParts(urlString: string): UrlWithStringQuery {
6469
// @see https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost
6570
if ('string' === typeof urlString) {
6671
// check is an uri
67-
return uriParse(urlString) // take apart the uri
72+
return uriParse(urlString, false, true) // take apart the uri
6873
}
6974
}
7075
return returnValue

0 commit comments

Comments
 (0)