Skip to main content
Api

Nuxt App Hooks

scripts:updated

  • Type: (ctx: { scripts: Record<string, NuxtDevToolsScriptInstance> }) => void | Promise<void>

Triggered in development when Nuxt Scripts updates the DevTools snapshot for a script. The payload includes lifecycle events and captured resource timing entries.

Nuxt Scripts uses this hook internally for DevTools. It is not emitted in production builds.

plugins/nuxt-scripts.ts
export default defineNuxtPlugin({
  setup() {
    useNuxtApp().hooks.hook('scripts:updated', (ctx) => {
      console.log('Scripts updated', ctx.scripts)
    })
  }
})

scripts:globals

  • Type: (globals: Record<string, Record<string, any>>) => void | Promise<void>

Runs in the generated scripts:init plugin immediately before it registers scripts.globals. The mutable globals map contains each declared key with build-time defaults merged with any NUXT_PUBLIC_SCRIPTS_GLOBALS_* environment overrides. Change an entry's src or attributes, or delete the entry, without rebuilding.

Static declarations keep their $scripts types and remain eligible for asset bundling. Deleting an entry, setting enabled: false, or clearing its src skips registration, and its $scripts value is undefined. The hook cannot add undeclared keys; call useScript() from your own plugin for those.

Register the listener in an enforce: 'pre' plugin so it runs before scripts:init.

plugins/nuxt-scripts-globals.ts
export default defineNuxtPlugin({
  enforce: 'pre',
  setup(nuxtApp) {
    const { tenant } = useRuntimeConfig().public
    nuxtApp.hooks.hook('scripts:globals', (globals) => {
      // Drop an integration this tenant doesn't use:
      if (!tenant.awinEnabled)
        delete globals.awin
      // Compute the src from runtime config:
      globals.trustedShops.src = `https://widgets.trustedshops.com/${tenant.trustedShopsId}.js`
    })
  }
})