Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

Commit 488479a

Browse files
authored
fix(nuxt): avoid injecting url helpers into globalThis (#9627)
1 parent 86ed4ef commit 488479a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/nuxt/src/core/nitro.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
2424
srcDir: nuxt.options.serverDir,
2525
dev: nuxt.options.dev,
2626
buildDir: nuxt.options.buildDir,
27+
imports: {
28+
imports: [
29+
{
30+
as: '__buildAssetsURL',
31+
name: 'buildAssetsURL',
32+
from: resolve(distDir, 'core/runtime/nitro/paths')
33+
},
34+
{
35+
as: '__publicAssetsURL',
36+
name: 'publicAssetsURL',
37+
from: resolve(distDir, 'core/runtime/nitro/paths')
38+
}
39+
]
40+
},
2741
esbuild: {
2842
options: {
2943
exclude: [

packages/vite/src/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { writeManifest } from './manifest'
1212

1313
export async function buildServer (ctx: ViteBuildContext) {
1414
const _resolve = (id: string) => resolveModule(id, { paths: ctx.nuxt.options.modulesDir })
15+
const helper = ctx.nuxt.options.nitro.imports !== false ? '' : 'globalThis.'
1516
const serverConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, {
1617
entry: ctx.entry,
1718
base: ctx.nuxt.options.dev
@@ -24,11 +25,11 @@ export async function buildServer (ctx: ViteBuildContext) {
2425
return { relative: true }
2526
}
2627
if (type === 'public') {
27-
return { runtime: `globalThis.__publicAssetsURL(${JSON.stringify(filename)})` }
28+
return { runtime: `${helper}__publicAssetsURL(${JSON.stringify(filename)})` }
2829
}
2930
if (type === 'asset') {
3031
const relativeFilename = filename.replace(withTrailingSlash(withoutLeadingSlash(ctx.nuxt.options.app.buildAssetsDir)), '')
31-
return { runtime: `globalThis.__buildAssetsURL(${JSON.stringify(relativeFilename)})` }
32+
return { runtime: `${helper}__buildAssetsURL(${JSON.stringify(relativeFilename)})` }
3233
}
3334
}
3435
},

0 commit comments

Comments
 (0)