diff --git a/packages/nuxt/src/app/nuxt.ts b/packages/nuxt/src/app/nuxt.ts index c705912c84..9a2cbf3587 100644 --- a/packages/nuxt/src/app/nuxt.ts +++ b/packages/nuxt/src/app/nuxt.ts @@ -286,6 +286,8 @@ export function createNuxtApp (options: CreateOptions) { nuxtApp.callHook('app:chunkError', { error: (event as Event & { payload: Error }).payload }) }) + window.useNuxtApp = window.useNuxtApp || useNuxtApp + // Log errors captured when running plugins, in the `app:created` and `app:beforeMount` hooks // as well as when mounting the app. const unreg = nuxtApp.hook('app:error', (...args) => { console.error('[nuxt] error caught during app initialization', ...args) }) diff --git a/packages/nuxt/src/app/types/augments.d.ts b/packages/nuxt/src/app/types/augments.d.ts index 48439981a1..d93c85760c 100644 --- a/packages/nuxt/src/app/types/augments.d.ts +++ b/packages/nuxt/src/app/types/augments.d.ts @@ -1,4 +1,4 @@ -import type { NuxtApp } from '../nuxt' +import type { NuxtApp, useNuxtApp } from '../nuxt' declare global { namespace NodeJS { @@ -14,6 +14,7 @@ declare global { interface Window { __NUXT__?: Record + useNuxtApp?: typeof useNuxtApp } } diff --git a/test/bundle.test.ts b/test/bundle.test.ts index c533359d13..d3dfa9c176 100644 --- a/test/bundle.test.ts +++ b/test/bundle.test.ts @@ -25,7 +25,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM it('default client bundle size', async () => { stats.client = await analyzeSizes('**/*.js', publicDir) - expect(roundToKilobytes(stats.client.totalBytes)).toMatchInlineSnapshot('"97.2k"') + expect(roundToKilobytes(stats.client.totalBytes)).toMatchInlineSnapshot('"97.3k"') expect(stats.client.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(` [ "_nuxt/entry.js",