fix(compiler-sfc): transformAssetUrls.base should not affect known module requests
fix https://github.com/vitejs/vite/issues/1343
This commit is contained in:
@@ -113,26 +113,20 @@ export const transformAssetUrl: NodeTransform = (
|
||||
}
|
||||
|
||||
const url = parseUrl(attr.value.content)
|
||||
if (options.base) {
|
||||
// explicit base - directly rewrite the url into absolute url
|
||||
// does not apply to absolute urls or urls that start with `@`
|
||||
// since they are aliases
|
||||
if (
|
||||
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 || '/'
|
||||
if (options.base && attr.value.content[0] === '.') {
|
||||
// explicit base - directly rewrite relative urls into absolute url
|
||||
// to avoid generating extra imports
|
||||
// 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 =
|
||||
host +
|
||||
(path.posix || path).join(basePath, url.path + (url.hash || ''))
|
||||
}
|
||||
// when packaged in the browser, path will be using the posix-
|
||||
// only version provided by rollup-plugin-node-builtins.
|
||||
attr.value.content =
|
||||
host +
|
||||
(path.posix || path).join(basePath, url.path + (url.hash || ''))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user