-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
feat(compiler-sfc): support transforming asset urls with full base url. #2477
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,12 +120,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 || '')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
// Notice how path.join() strips the second slash from http://
// This is the problem that is solved by this pull request.
path.join("http://localhost:3000/src/assets", "logo.png") === 'http:/localhost:3000/src/assets/logo.png') |
||
} | ||
return | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice the fully qualified URL for the img src - this was previously not possible when using
options.base
, as far as I could tell