diff --git a/packages/app/src/_templates/plugins.mjs b/packages/app/src/_templates/plugins.mjs index ee444f12e9..2093abfd6b 100644 --- a/packages/app/src/_templates/plugins.mjs +++ b/packages/app/src/_templates/plugins.mjs @@ -10,14 +10,15 @@ const commonPlugins = [ <%= app.plugins.filter(p => !p.mode || p.mode === 'all').map(p => utils.importName(p.src)).join(',\n ') %> ] -export const clientPluigns = [ - ...commonPlugins,<%= app.plugins.filter(p => p.mode === 'client').map(p => utils.importName(p.src)).join(',\n ') %> +export const clientPlugins = [ + ...commonPlugins, + <%= app.plugins.filter(p => p.mode === 'client').map(p => utils.importName(p.src)).join(',\n ') %> ] -export const serverPluigns = [ +export const serverPlugins = [ ...commonPlugins, preload, <%= app.plugins.filter(p => p.mode === 'server').map(p => utils.importName(p.src)).join(',\n ') %> ] -export default process.client ? clientPluigns : serverPluigns +export default process.client ? clientPlugins : serverPlugins diff --git a/packages/nitro/src/runtime/app/nitro.client.js b/packages/nitro/src/runtime/app/nitro.client.js index 726d881c78..ea48f87748 100644 --- a/packages/nitro/src/runtime/app/nitro.client.js +++ b/packages/nitro/src/runtime/app/nitro.client.js @@ -3,3 +3,5 @@ import { $fetch } from 'ohmyfetch' if (!globalThis.$fetch) { globalThis.$fetch = $fetch } + +export default () => {} diff --git a/packages/nuxt3/src/nitro.ts b/packages/nuxt3/src/nitro.ts index c88c872f82..fbd5b22be6 100644 --- a/packages/nuxt3/src/nitro.ts +++ b/packages/nuxt3/src/nitro.ts @@ -18,6 +18,11 @@ export function initNitro (nuxt: Nuxt) { nuxt.hooks.addHooks(nitroDevContext.nuxtHooks) nuxt.hook('close', () => nitroDevContext._internal.hooks.callHook('close')) + // Add nitro client plugin (to inject $fetch helper) + nuxt.hook('app:resolve', (app) => { + app.plugins.push({ src: require.resolve('@nuxt/nitro/dist/runtime/app/nitro.client') }) + }) + // Expose process.env.NITRO_PRESET nuxt.options.env.NITRO_PRESET = nitroContext.preset