Skip to content

Commit

Permalink
fix: find vite client path automatically, close #352
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 1, 2023
1 parent c52ba49 commit b78d04f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/devtools/client/composables/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createBirpc } from 'birpc'
import { parse, stringify } from 'flatted'
import { createHotContext } from 'vite-hot-client'
import { tryCreateHotContext } from 'vite-hot-client'
import type { ClientFunctions, ServerFunctions } from '../../src/types'
import { WS_EVENT_NAME } from '../../src/constant'

Expand Down Expand Up @@ -41,7 +41,18 @@ export const rpc = createBirpc<ServerFunctions>(clientFunctions, {
})

async function connectVite() {
const hot = await createHotContext()
// @ts-expect-error no types

let base = window.__NUXT__.config?.app?.baseURL
if (base && !base.endsWith('/'))
base += '/'
const hot = await tryCreateHotContext(undefined, [
...(base
? [`${base}_nuxt/`, base]
: []),
'/_nuxt/',
'/',
])

if (!hot)
throw new Error('Unable to connect to devtools')
Expand Down

0 comments on commit b78d04f

Please sign in to comment.