fix(vite): update regex to handle new vite output format (#4014)

This commit is contained in:
Daniel Roe 2022-04-01 11:15:00 +01:00 committed by GitHub
parent 4c77c88325
commit 51f3bbfd23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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