From bc725133d50e1e5b6cb2deba997a889d412f5596 Mon Sep 17 00:00:00 2001 From: Jonas <30421456+jonaskuske@users.noreply.github.com> Date: Tue, 9 Aug 2022 11:48:40 +0200 Subject: [PATCH 1/2] fix: allow full hostnames in asset url base modeled after https://github.com/vuejs/core/blob/a95554d35c65e5bfd0bf9d1c5b908ae789345a6d/packages/compiler-sfc/src/templateTransformAssetUrl.ts#L120-L130 --- .../src/templateCompilerModules/utils.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/compiler-sfc/src/templateCompilerModules/utils.ts b/packages/compiler-sfc/src/templateCompilerModules/utils.ts index 3e635b00207..be202b013f2 100644 --- a/packages/compiler-sfc/src/templateCompilerModules/utils.ts +++ b/packages/compiler-sfc/src/templateCompilerModules/utils.ts @@ -24,12 +24,20 @@ 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, - uriParts.path + (uriParts.hash || '') - )}"` + return ( + host + + `"${(path.posix || path).join( + basePath, + uriParts.path + (uriParts.hash || '') + )}"` + ) } } @@ -64,7 +72,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 From 74cfd2b2ef15ebb228da3afca3a68d2c22b67098 Mon Sep 17 00:00:00 2001 From: Jonas <30421456+jonaskuske@users.noreply.github.com> Date: Tue, 9 Aug 2022 12:20:17 +0200 Subject: [PATCH 2/2] fix: insert quote at correct position in asset url --- .../compiler-sfc/src/templateCompilerModules/utils.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/compiler-sfc/src/templateCompilerModules/utils.ts b/packages/compiler-sfc/src/templateCompilerModules/utils.ts index be202b013f2..8a2d19c6ce7 100644 --- a/packages/compiler-sfc/src/templateCompilerModules/utils.ts +++ b/packages/compiler-sfc/src/templateCompilerModules/utils.ts @@ -31,13 +31,10 @@ export function urlToRequire( const basePath = base.path || '/' // when packaged in the browser, path will be using the posix- // only version provided by rollup-plugin-node-builtins. - return ( - host + - `"${(path.posix || path).join( - basePath, - uriParts.path + (uriParts.hash || '') - )}"` - ) + return `"${host}${(path.posix || path).join( + basePath, + uriParts.path + (uriParts.hash || '') + )}"` } }