mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): avoid injecting url helpers into globalThis
(#9627)
This commit is contained in:
parent
86ed4ef1f4
commit
488479ab1b
@ -24,6 +24,20 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
||||
srcDir: nuxt.options.serverDir,
|
||||
dev: nuxt.options.dev,
|
||||
buildDir: nuxt.options.buildDir,
|
||||
imports: {
|
||||
imports: [
|
||||
{
|
||||
as: '__buildAssetsURL',
|
||||
name: 'buildAssetsURL',
|
||||
from: resolve(distDir, 'core/runtime/nitro/paths')
|
||||
},
|
||||
{
|
||||
as: '__publicAssetsURL',
|
||||
name: 'publicAssetsURL',
|
||||
from: resolve(distDir, 'core/runtime/nitro/paths')
|
||||
}
|
||||
]
|
||||
},
|
||||
esbuild: {
|
||||
options: {
|
||||
exclude: [
|
||||
|
@ -12,6 +12,7 @@ import { writeManifest } from './manifest'
|
||||
|
||||
export async function buildServer (ctx: ViteBuildContext) {
|
||||
const _resolve = (id: string) => resolveModule(id, { paths: ctx.nuxt.options.modulesDir })
|
||||
const helper = ctx.nuxt.options.nitro.imports !== false ? '' : 'globalThis.'
|
||||
const serverConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, {
|
||||
entry: ctx.entry,
|
||||
base: ctx.nuxt.options.dev
|
||||
@ -24,11 +25,11 @@ export async function buildServer (ctx: ViteBuildContext) {
|
||||
return { relative: true }
|
||||
}
|
||||
if (type === 'public') {
|
||||
return { runtime: `globalThis.__publicAssetsURL(${JSON.stringify(filename)})` }
|
||||
return { runtime: `${helper}__publicAssetsURL(${JSON.stringify(filename)})` }
|
||||
}
|
||||
if (type === 'asset') {
|
||||
const relativeFilename = filename.replace(withTrailingSlash(withoutLeadingSlash(ctx.nuxt.options.app.buildAssetsDir)), '')
|
||||
return { runtime: `globalThis.__buildAssetsURL(${JSON.stringify(relativeFilename)})` }
|
||||
return { runtime: `${helper}__buildAssetsURL(${JSON.stringify(relativeFilename)})` }
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user