fix(vite): don't terminate with escaped delimiters (#5409)

This commit is contained in:
Daniel Roe 2022-06-10 16:17:11 +01:00 committed by GitHub
parent fbcbac01d6
commit 8831e4a4b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -89,7 +89,7 @@ export const DynamicBasePlugin = createUnplugin(function (options: DynamicBasePl
s.replace(/from *['"]\/__NUXT_BASE__(\/[^'"]*)['"]/g, 'from "$1"')
// Dynamically compute string URLs featuring baseURL
const delimiterRE = /(?<!(const base = |from *))(`([^`]*)\/__NUXT_BASE__\/([^`]*)`|'([^\n']*)\/__NUXT_BASE__\/([^\n']*)'|"([^\n"]*)\/__NUXT_BASE__\/([^\n"]*)")/g
const delimiterRE = /(?<!(const base = |from *))((?<!\\)`([^`]*)\/__NUXT_BASE__\/([^`]*)(?<!\\)`|(?<!\\)'([^\n']*)\/__NUXT_BASE__\/([^\n']*)(?<!\\)'|(?<!\\)"([^\n"]*)\/__NUXT_BASE__\/([^\n"]*)(?<!\\)")/g
/* eslint-disable-next-line no-template-curly-in-string */
s.replace(delimiterRE, r => '`' + r.replace(/\/__NUXT_BASE__\//g, '${__publicAssetsURL()}').slice(1, -1) + '`')

View File

@ -349,6 +349,8 @@ describe('dynamic paths', () => {
[
"./logo.svg",
"../public.svg",
"../public.svg",
"../public.svg",
]
`)
})

View File

@ -13,8 +13,14 @@ import logo from '~/assets/logo.svg'
<style>
#__nuxt {
background-image: url('~/assets/logo.svg');
@font-face {
src: url("/public.svg") format("woff2");
}
}
body {
background-image: url('/public.svg');
@font-face {
src: url('/public.svg') format('woff2');
}
}
</style>