Skip to content

Commit e592b98

Browse files
committedAug 3, 2024·
fix: allow empty ignoredHostnames to remove localhost (fixes #30)
1 parent 34d9e4b commit e592b98

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed
 

Diff for: ‎src/module.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
} from '@nuxt/kit'
99
import { name, version } from '../package.json'
1010

11+
const DEFAULT_HOSTNAMES = ['localhost']
12+
1113
export interface ModuleOptions {
1214
/**
1315
* Whether the tracker shall be enabled.
@@ -103,7 +105,7 @@ export default defineNuxtModule<ModuleOptions>({
103105
enabled: true,
104106
hashMode: false,
105107
domain: '',
106-
ignoredHostnames: ['localhost'],
108+
ignoredHostnames: [],
107109
ignoreSubDomains: false,
108110
trackLocalhost: false,
109111
apiHost: 'https://plausible.io',
@@ -118,11 +120,14 @@ export default defineNuxtModule<ModuleOptions>({
118120
// Dedupe `ignoredHostnames` items
119121
options.ignoredHostnames = Array.from(new Set(options.ignoredHostnames))
120122

123+
// Add default hostnames if `ignoredHostnames` is empty
124+
if (options.ignoredHostnames.length === 0) {
125+
options.ignoredHostnames = DEFAULT_HOSTNAMES
126+
}
127+
121128
// Migrate `trackLocalhost` to `ignoredHostnames`
122129
if (options.trackLocalhost) {
123-
logger.warn(
124-
'The `trackLocalhost` option has been deprecated. Please use `ignoredHostnames` instead.',
125-
)
130+
logger.warn('The `trackLocalhost` option has been deprecated. Please use `ignoredHostnames` instead.')
126131
options.ignoredHostnames = options.ignoredHostnames.filter(
127132
domain => domain !== 'localhost',
128133
)

0 commit comments

Comments
 (0)
Please sign in to comment.