Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ Setting a value for the required `id` option is enough in most cases.

Below is the complete list of options:

| Option | Type | Default | Required |
| :-- | :-- | :-- | :-- |
| id | `String` | `''` | True |
| dev | `Boolean` | `true` | False |
| enablePinia | `Boolean` | `true` | False |
| release | `String` | `null` | False |
| consoleEnabled | `Boolean` | `true` | False |
| networkEnabled | `Boolean` | `true` | False |
| networkRequestSanitizer | `Function` | - | False |
| networkResponseSanitizer | `Function` | - | False |
| domEnabled | `Boolean` | `true` | False |
| inputSanitizer | `Boolean` | `false` | False |
| textSanitizer | `Boolean` | `false` | False |
| baseHref | `String` | `null` | False |
| shouldCaptureIP | `Boolean` | `true` | False |
| rootHostname | `String` | `null` | False |
| shouldDebugLog | `Boolean` | `true` | False |
| mergeIframes | `Boolean` | `false` | False |
| Option | Type | Default | Required |
| :----------------------- | :--------- | :------ | :------- |
| id | `String` | `''` | True |
| dev | `Boolean` | `true` | False |
| enablePinia | `Boolean` | `true` | False |
| release | `String` | `null` | False |
| consoleEnabled | `Boolean` | `true` | False |
| networkEnabled | `Boolean` | `true` | False |
| networkRequestSanitizer | `Function` | - | False |
| networkResponseSanitizer | `Function` | - | False |
| domEnabled | `Boolean` | `true` | False |
| inputSanitizer | `Boolean` | `false` | False |
| textSanitizer | `Boolean` | `false` | False |
| baseHref | `String` | `null` | False |
| shouldCaptureIP | `Boolean` | `true` | False |
| rootHostname | `String` | `null` | False |
| shouldDebugLog | `Boolean` | `true` | False |
| mergeIframes | `Boolean` | `false` | False |

This is an example containing the default values for the options:

Expand Down Expand Up @@ -135,7 +135,8 @@ export default defineNuxtConfig({
## Development

- Clone this repository
- Install dependencies using `yarn install`
- Install dependencies using `yarn install` (yarn 1)
- Prepare playground by running `yarn run prepack`
- Start development server using `yarn run dev`
- Point your browser to `http://localhost:3000`

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"test": "yarn dev:prepare && vitest run test",
"lint": "eslint --ext .js,.ts,.vue .",
"lint:fix": "eslint --fix --ext .js,.ts,.vue .",
"typing": "nuxi typecheck",
"release": "yarn lint && yarn test && yarn prepack && yarn standard-version && git push --follow-tags && npm publish"
},
"dependencies": {
Expand All @@ -45,7 +46,10 @@
"@nuxtjs/eslint-config-typescript": "latest",
"eslint": "^8.49.0",
"nuxt": "^3.7.2",
"pinia": "^3.0.1",
"standard-version": "^9.3.2",
"typescript": ">=4.3.5 <5.4.0",
"vitest": "^0.34.4"
}
},
"packageManager": "[email protected]"
}
2 changes: 1 addition & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineNuxtConfig } from 'nuxt/config'
import NuxtLogRocket from '..'
import NuxtLogRocket from '../src/module'

export default defineNuxtConfig({
modules: [NuxtLogRocket],
Expand Down
19 changes: 16 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { defu } from 'defu'
import {
isNuxt3,
isNuxtMajorVersion,
addPlugin,
addImports,
useLogger,
createResolver,
defineNuxtModule
} from '@nuxt/kit'
import type LogRocket from 'logrocket'
import { name, version } from '../package.json'

const logger = useLogger('nuxt-logrocket')
Expand Down Expand Up @@ -135,7 +136,7 @@ export default defineNuxtModule<ModuleOptions>({
}),
setup (opts, nuxt) {
const options = defu<ModuleOptions, any>(
isNuxt3()
isNuxtMajorVersion(3, nuxt)
? nuxt.options.runtimeConfig.public?.logRocket
// @ts-ignore
: nuxt.options.publicRuntimeConfig.logRocket || {},
Expand All @@ -144,7 +145,7 @@ export default defineNuxtModule<ModuleOptions>({

nuxt.options.alias.LogRocket = 'LogRocket'

if (isNuxt3()) {
if (isNuxtMajorVersion(3, nuxt)) {
// @ts-ignore
nuxt.options.runtimeConfig.public.logRocket = options
} else {
Expand Down Expand Up @@ -178,3 +179,15 @@ declare module '@nuxt/schema' {
};
}
}

declare module '#app' {
interface NuxtApp {
$LogRocket: typeof LogRocket
}
}

declare module 'vue' {
interface ComponentCustomProperties {
$LogRocket: typeof LogRocket
}
}
10 changes: 5 additions & 5 deletions src/runtime/plugin.client.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import LogRocket from '#imports'
import { LogRocket, defineNuxtPlugin, useRuntimeConfig } from '#imports'

// type inference required to prevent TS4082 error for 'LR.LogRocket'
interface NuxtLR { logRocket: Omit<typeof LogRocket, 'init' | 'reduxMiddleware'>}
export default defineNuxtPlugin<NuxtLR>(({ pinia }) => {
export default defineNuxtPlugin(({ pinia }) => {
const opts = useRuntimeConfig()?.public?.logRocket

if (!opts?.id || (!opts?.dev && !(process.env.NODE_ENV === 'production'))) { return }
if (!opts?.id || (!opts?.dev && !(process.env.NODE_ENV === 'production'))) {
return
}

LogRocket.init(opts?.id, opts?.config)

Expand Down
Loading