import type { Plugin } from '@nuxt/types' ; import type { SetupContext } from '@vue/composition-api' ; import { getHeadOptions } from './meta' ; import { reqRefs } from './req-ref' ; import { setSSRContext } from './ssr-ref' ; type SetupFunction = ( this : void , props : Record < string , unknown > , ctx : SetupContext ) => void | Record < any , any > ; let globalSetup ; param fn example export const onGlobalSetup = ( fn ) => { globalSetup . add ( fn ) ; } ; private export const setMetaPlugin = context => { const { head } = context . app ; Object . assign ( context . app , getHeadOptions ( { head : head as any } ) ) ; } ; private export const globalPlugin = context => { if ( process . server ) { reqRefs . forEach ( reset => reset ( ) ) ; setSSRContext ( context . app ) ; } const { setup } = context . app ; globalSetup = new Set < SetupFunction > ( ) ; context . app . setup = function ( ... args ) { let result = { } ; if ( setup instanceof Function ) { result = setup ( ... args ) || { } ; } for ( const fn of globalSetup ) { result = { ... result , ... ( fn . call ( this , ... args ) || { } ) } ; } return result ; } ; } ;