Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Mar 21, 2024
1 parent 3ae21f2 commit ad13d47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ Plus Nuxt goodies:
- 🕵️ Privacy Features - Trigger scripts loading on cookie consent, honour DoNotTrack.
- 🪵 DevTools integration - see all your loaded scripts with function logs

## Background

Loading third-party IIFE scripts using `useHead` composable is easy. However,
things start getting more complicated quickly around SSR, lazy loading, and type safety.

Nuxt Scripts was created to solve these issues and more with the goal of making third-party scripts more performant,
have better privacy and be better DX overall.

## Quick Start

To get started, simply run:
Expand All @@ -43,26 +51,17 @@ If you want to get a feel for how the module works, you can load the `js-confett

```ts
type JSConfettiApi = { addConfetti: (options?: { emojis: string[] }) => void }

Check failure on line 53 in README.md

View workflow job for this annotation

GitHub Actions / ci

Use an `interface` instead of a `type`

const { addConfetti } = useScript<JSConfettiApi>('https://cdn.jsdelivr.net/npm/js-confetti@latest/dist/js-confetti.browser.js', {
trigger: 'idle', // load on onNuxtReady
assetStrategy: 'bundle', //
assetStrategy: 'bundle', // script will be served from your server instead of cdn.jsdelivr.net
use() {
return new window.JSConfetti()
},
})
// will run once the script loads
// useScript is non-blocking, this will run once the script loads
addConfetti({ emojis: ['🌈', '⚡️', '💥', '', '💫', '🌸'] })
```

## Background

Loading third-party IIFE scripts using `useHead` composable is easy. However,
things start getting more complicated quickly around SSR, lazy loading, and type safety.

Nuxt Scripts was created to solve these issues and more with the goal of making third-party scripts more performant,
have better privacy and be better DX overall.

## Guides

### Bundling Scripts
Expand Down
6 changes: 1 addition & 5 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default defineNuxtModule<ModuleOptions>({
name: '@nuxt/scripts',
configKey: 'scripts',
compatibility: {
nuxt: '^3.9.0',
nuxt: '^3.11.1',
bridge: false,
},
},
Expand Down Expand Up @@ -84,10 +84,6 @@ export default defineNuxtModule<ModuleOptions>({
},
}))

nuxt.hook('build:manifest', () => {
// TODO ?
})

if (nuxt.options.dev)
setupDevToolsUI(config, resolve)
},
Expand Down

0 comments on commit ad13d47

Please sign in to comment.