mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(vite): only apply relative url fix to css assets (#2930)
This commit is contained in:
parent
4b1ea5741e
commit
d0bcc3fc82
@ -18,12 +18,13 @@ export const RelativeAssetPlugin = function (): Plugin {
|
||||
|
||||
for (const file in bundle) {
|
||||
const asset = bundle[file]
|
||||
if (asset.type === 'asset') {
|
||||
if (asset.type === 'asset' && typeof asset.source === 'string' && asset.fileName.endsWith('.css')) {
|
||||
const depth = file.split('/').length - 1
|
||||
const assetBase = depth === 0 ? '.' : Array.from({ length: depth }).map(() => '..').join('/')
|
||||
asset.source = asset.source.toString().replace(assetRE, r => r.replace(/\/__NUXT_BASE__/g, assetBase))
|
||||
const publicBase = Array.from({ length: depth + 1 }).map(() => '..').join('/')
|
||||
asset.source = asset.source.toString().replace(/\/__NUXT_BASE__/g, publicBase)
|
||||
asset.source = asset.source
|
||||
.replace(assetRE, r => r.replace(/\/__NUXT_BASE__/g, assetBase))
|
||||
.replace(/\/__NUXT_BASE__/g, publicBase)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user