Skip to content

Commit 51b8d2e

Browse files
fix: disable plugin on ssr
1 parent 87b5dfa commit 51b8d2e

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ const nuxtModule: Module<ModuleOptions> = function (moduleOptions) {
4646
}
4747
})
4848

49-
plugins.push(resolve(this.options.buildDir, dst))
49+
plugins.push({
50+
src: resolve(this.options.buildDir, dst),
51+
ssr: false
52+
})
5053

5154
// Extend echo with plugins
5255
if (options.plugins) {
53-
options.plugins.forEach(p => plugins.push(p))
56+
options.plugins.forEach(p => plugins.push({ src: p, ssr: false }))
5457

5558
delete options.plugins
5659
}

src/runtime/plugin.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ import { Echo } from '~echo'
77
export default async function (ctx, inject) {
88
const echoOptions = typeof options === 'function' ? await options(ctx) : options
99

10-
if (process.client) {
11-
<% if (options.broadcaster === 'pusher' && !options.encrypted) { %>
12-
if (!window.Pusher) window.Pusher = require('pusher-js')
13-
<% } %>
10+
<% if (options.broadcaster === 'pusher' && !options.encrypted) { %>
11+
if (!window.Pusher) window.Pusher = require('pusher-js')
12+
<% } %>
1413

15-
<% if (options.broadcaster === 'pusher' && options.encrypted) { %>
16-
if (!window.Pusher) window.Pusher = require('pusher-js/with-encryption')
17-
<% } %>
14+
<% if (options.broadcaster === 'pusher' && options.encrypted) { %>
15+
if (!window.Pusher) window.Pusher = require('pusher-js/with-encryption')
16+
<% } %>
1817

19-
<% if (options.broadcaster === 'socket.io') { %>
20-
if (!window.io) window.io = require('socket.io-client')
21-
<% } %>
22-
}
18+
<% if (options.broadcaster === 'socket.io') { %>
19+
if (!window.io) window.io = require('socket.io-client')
20+
<% } %>
2321

2422
const echo = new Echo(ctx, echoOptions)
2523
await echo.init()

0 commit comments

Comments
 (0)