feat(nuxt): expose useNuxtApp to window for convenience (#21636)

This commit is contained in:
Daniel Roe 2023-06-19 17:17:15 +01:00 committed by GitHub
parent 190760719c
commit 0e575ad5ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 2 deletions

View File

@ -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) })

View File

@ -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<string, any>
useNuxtApp?: typeof useNuxtApp
}
}

View File

@ -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",