1
1
import Echo from 'laravel-echo'
2
- import Pusher from 'pusher-js'
3
2
import type { Channel , Options , ChannelAuthorizationCallback } from 'pusher-js'
4
3
import type { ChannelAuthorizationData } from 'pusher-js/types/src/core/auth/options'
5
4
import { createConsola , type ConsolaInstance } from 'consola'
@@ -11,7 +10,6 @@ import { defineNuxtPlugin, createError, useCookie } from '#app'
11
10
declare global {
12
11
interface Window {
13
12
Echo : Echo
14
- Pusher : typeof Pusher
15
13
}
16
14
}
17
15
@@ -98,9 +96,9 @@ function prepareEchoOptions(config: ModuleOptions, logger: ConsolaInstance) {
98
96
99
97
const authorizer = config . authentication
100
98
? createAuthorizer (
101
- config . authentication as Required < Authentication > ,
102
- logger
103
- )
99
+ config . authentication as Required < Authentication > ,
100
+ logger
101
+ )
104
102
: undefined
105
103
106
104
// Create a Pusher instance
@@ -133,11 +131,13 @@ function prepareEchoOptions(config: ModuleOptions, logger: ConsolaInstance) {
133
131
}
134
132
}
135
133
136
- export default defineNuxtPlugin ( ( _nuxtApp ) => {
134
+ export default defineNuxtPlugin ( async ( _nuxtApp ) => {
137
135
const config = useEchoConfig ( )
138
136
const logger = createEchoLogger ( config . logLevel )
139
137
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
141
141
window . Echo = new Echo ( prepareEchoOptions ( config , logger ) )
142
142
143
143
logger . debug ( 'Laravel Echo client initialized' )
0 commit comments