From 5c742eb2e0d8dad268fb29ed4f92d286b5e0f4b5 Mon Sep 17 00:00:00 2001 From: Jonas <30421456+jonaskuske@users.noreply.github.com> Date: Mon, 15 Aug 2022 03:37:08 +0200 Subject: [PATCH] fix(compiler-sfc): allow full hostnames in asset url base (#12732) fix #12731 --- .../compiler-sfc/src/templateCompilerModules/utils.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/compiler-sfc/src/templateCompilerModules/utils.ts b/packages/compiler-sfc/src/templateCompilerModules/utils.ts index 3e635b00207..8a2d19c6ce7 100644 --- a/packages/compiler-sfc/src/templateCompilerModules/utils.ts +++ b/packages/compiler-sfc/src/templateCompilerModules/utils.ts @@ -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 || '') )}"` } @@ -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