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

Commit

Permalink
fix(nuxt): avoid injecting url helpers into globalThis (#9627)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jan 14, 2023
1 parent 86ed4ef commit 488479a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions packages/nuxt/src/core/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
5 changes: 3 additions & 2 deletions packages/vite/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)})` }
}
}
},
Expand Down

0 comments on commit 488479a

Please sign in to comment.