fix(vite): clean up dynamic paths (#4130)

This commit is contained in:
Daniel Roe 2022-04-06 15:15:36 +01:00 committed by GitHub
parent fe8e325541
commit 3ea39e0745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -33,6 +33,12 @@ export const RelativeAssetPlugin = function (): Plugin {
.replace(assetRE, r => r.replace(/\/__NUXT_BASE__/g, assetBase))
.replace(/\/__NUXT_BASE__/g, publicBase)
}
if (asset.type === 'chunk' && typeof asset.code === 'string') {
asset.code = asset.code
.replace(/`\$\{(_?_?publicAssetsURL|buildAssetsURL|)\(\)\}([^`]*)`/g, '$1(`$2`)')
.replace(/"\/__NUXT_BASE__\/([^"]*)"\.replace\("\/__NUXT_BASE__", ""\)/g, '"$1"')
.replace(/'\/__NUXT_BASE__\/([^']*)'\.replace\("\/__NUXT_BASE__", ""\)/g, '"$1"')
}
}
}
}

View File

@ -13,6 +13,7 @@ import { prepareDevServerEntry } from './vite-node'
import { isCSS, isDirectory, readDirRecursively } from './utils'
import { bundleRequest } from './dev-bundler'
import { writeManifest } from './manifest'
import { RelativeAssetPlugin } from './plugins/dynamic-base'
export async function buildServer (ctx: ViteBuildContext) {
const _resolve = id => resolveModule(id, { paths: ctx.nuxt.options.modulesDir })
@ -74,6 +75,7 @@ export async function buildServer (ctx: ViteBuildContext) {
},
plugins: [
cacheDirPlugin(ctx.nuxt.options.rootDir, 'server'),
RelativeAssetPlugin(),
vuePlugin(ctx.config.vue),
viteJsxPlugin()
]