-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
152 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: Nuxt Config | ||
description: Configure Nuxt Scripts using your Nuxt Config. | ||
--- | ||
|
||
## `registry` | ||
|
||
- Type: `ScriptRegistry` | ||
|
||
Global registry scripts that should be loaded. | ||
|
||
See the [Script Registry](/scripts) for more details. | ||
|
||
## `defaultScriptOptions` | ||
|
||
- Type: `NuxtUseScriptOptions` | ||
- Default: `{ trigger: 'onNuxtReady' }` | ||
|
||
Default options for scripts. See the [useScript](/use-script) documentation for more details. | ||
|
||
## `globals` | ||
|
||
- Type: `(NuxtUseScriptInput | [NuxtUseScriptInput, NuxtUseScriptOptions])[]` | ||
- Default: `[]` | ||
|
||
Global scripts that should be loaded on all pages. This is a configuration for the [useScript](/use-script) composable. | ||
|
||
See the [Globals](/guides/global) documentation for more details. | ||
|
||
## `assets` | ||
|
||
- Type: `object` | ||
- Default: `{ prefix: '/_scripts/', strategy: 'public' }` | ||
|
||
Controls the way scripts are bundled to be served by Nuxt. | ||
|
||
See the [Bundling](/guides/bundling) documentation for more details. | ||
|
||
## `enabled` | ||
|
||
- Type: `boolean` | ||
- Default: `true` | ||
|
||
Disables the Nuxt Scripts module. | ||
|
||
## `debug` | ||
|
||
- Type: `boolean` | ||
- Default: `false` | ||
|
||
Enable to see debug logs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
title: Nuxt App Hooks | ||
description: Use Nuxt App hooks to extend the Nuxt Scripts runtime behavior. | ||
--- | ||
|
||
## `scripts:updated` | ||
|
||
- Type: `async (ctx: { scripts: ScriptRegistry }) => HookResult` | ||
|
||
Triggered after the script status is updated. | ||
|
||
This is used internally for the DevTools but can be used however you see fit. | ||
|
||
```ts [plugins/nuxt-scripts.ts] | ||
export default defineNuxtPlugin({ | ||
setup() { | ||
useNuxtApp().hooks.hook('scripts:updated', (ctx) => { | ||
console.log('Scripts updated', ctx.scripts) | ||
}) | ||
} | ||
}) | ||
``` | ||
|
||
## `script:instance-fn` | ||
|
||
- Type: `(ctx: { script: ScriptInstance<any>, fn: string | symbol, args: any, exists: boolean }) => HookResult` | ||
|
||
This is exposed only from Unhead, it's fired when accessing properties via the proxy instance. | ||
|
||
This is also used internally for the DevTools but can be used however you see fit. | ||
|
||
```ts | ||
export default defineNuxtPlugin({ | ||
setup() { | ||
const head = injectHead() | ||
head.hooks.hook('script:instance-fn', ({ fn, args }) => { | ||
console.log('Function called:', ctx) | ||
}) | ||
const { doSomething } = useScript() | ||
doSomething() // Function called: doSomething | ||
} | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: Nuxt Hooks | ||
description: Use Nuxt hooks to extend the Nuxt Scripts module. | ||
--- | ||
|
||
## `scripts:registry` | ||
|
||
- Type: `async (ctx: { registry: ScriptRegistry }) => HookResult` | ||
|
||
Add registry scripts at build, allowing them to be loaded via `scripts.registry` and bundled if available. | ||
|
||
This is intended to be used by modules. | ||
|
||
```ts [module.ts] | ||
export default defineNuxtModule({ | ||
setup() { | ||
nuxt.hooks.hook('scripts:registry', async (ctx) => { | ||
ctx.registry.add({ | ||
// used in DevTools | ||
label: 'My Custom Script', | ||
logo: `<svg class="w-10 h-10" xmlns="http://www.w3.org/2000/svg" width="28.85" height="32" viewBox="0 0 256 284"><path fill="#F9AB00" d="M256.003 247.933a35.224 35.224 0 0 1-39.376 35.161c-18.044-2.67-31.266-18.371-30.826-36.606V36.845C185.365 18.591 198.62 2.881 216.687.24a35.221 35.221 0 0 1 39.316 35.16z"/><path fill="#E37400" d="M35.101 213.193c19.386 0 35.101 15.716 35.101 35.101c0 19.386-15.715 35.101-35.101 35.101S0 267.68 0 248.295c0-19.386 15.715-35.102 35.101-35.102m92.358-106.387c-19.477 1.068-34.59 17.406-34.137 36.908v94.285c0 25.588 11.259 41.122 27.755 44.433a35.161 35.161 0 0 0 42.146-34.56V142.089a35.222 35.222 0 0 0-35.764-35.282"/></svg>`, | ||
// if the script can be bundled we need to define a resolver | ||
scriptBundling: 'https://cdn.jsdelivr.net/npm/[email protected]', | ||
// how to load the script, will be added as an auto import | ||
import: { | ||
name: 'useScriptMyCustomScript', | ||
from: resolve('./runtime/scripts/my-custom-script'), | ||
}, | ||
}) | ||
}) | ||
}, | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
icon: i-ph-star-duotone | ||
title: API | ||
title: Nuxt API |