Skip to content

Commit 3083116

Browse files
committed
fix: use lazy load for pusher
1 parent ecca4f4 commit 3083116

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/runtime/plugin.client.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Echo from 'laravel-echo'
2-
import Pusher from 'pusher-js'
32
import type { Channel, Options, ChannelAuthorizationCallback } from 'pusher-js'
43
import type { ChannelAuthorizationData } from 'pusher-js/types/src/core/auth/options'
54
import { createConsola, type ConsolaInstance } from 'consola'
@@ -11,7 +10,6 @@ import { defineNuxtPlugin, createError, useCookie } from '#app'
1110
declare global {
1211
interface Window {
1312
Echo: Echo
14-
Pusher: typeof Pusher
1513
}
1614
}
1715

@@ -98,9 +96,9 @@ function prepareEchoOptions(config: ModuleOptions, logger: ConsolaInstance) {
9896

9997
const authorizer = config.authentication
10098
? createAuthorizer(
101-
config.authentication as Required<Authentication>,
102-
logger
103-
)
99+
config.authentication as Required<Authentication>,
100+
logger
101+
)
104102
: undefined
105103

106104
// Create a Pusher instance
@@ -133,11 +131,13 @@ function prepareEchoOptions(config: ModuleOptions, logger: ConsolaInstance) {
133131
}
134132
}
135133

136-
export default defineNuxtPlugin((_nuxtApp) => {
134+
export default defineNuxtPlugin(async (_nuxtApp) => {
137135
const config = useEchoConfig()
138136
const logger = createEchoLogger(config.logLevel)
139137

140-
window.Pusher = Pusher
138+
const pusher = await import('pusher-js')
139+
// @ts-expect-error Pusher is not defined on Window
140+
window.Pusher = pusher.default || pusher
141141
window.Echo = new Echo(prepareEchoOptions(config, logger))
142142

143143
logger.debug('Laravel Echo client initialized')

0 commit comments

Comments
 (0)