-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fa51c6
commit f99a3f2
Showing
10 changed files
with
259 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { activeAppRecord } from '../setup/vue-devtools' | ||
|
||
export function useVueDevToolsState() { | ||
return { | ||
activeAppRecord, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script setup lang="ts"> | ||
import { Pinia } from '@vue/devtools-applet' | ||
import '@vue/devtools-applet/style.css' | ||
definePageMeta({ | ||
icon: 'i-logos-pinia', | ||
title: 'Pinia', | ||
layout: 'full', | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="h-full w-full"> | ||
<Pinia /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { HandShakeServer, getDevToolsState, initDevToolsSeparateWindow, initDevToolsSeparateWindowBridge, onDevToolsStateUpdated, setupDevToolsBridge } from '@vue/devtools-core' | ||
import type { AppRecord } from '@vue/devtools-kit' | ||
import { toggleHighPerfMode } from '@vue/devtools-kit' | ||
|
||
export type DevtoolsBridgeAppRecord = Pick<AppRecord, 'name' | 'id' | 'version' | 'routerId' | 'moduleDetectives'> | ||
|
||
const appRecords = ref<Array<DevtoolsBridgeAppRecord>>([]) | ||
const activeAppRecordId = ref<string | null>(null) | ||
export const activeAppRecord = computed(() => appRecords.value.find(r => r.id === activeAppRecordId.value)) | ||
|
||
export function initVueDevToolsState() { | ||
getDevToolsState().then((_data) => { | ||
const data = _data! | ||
appRecords.value = data.appRecords | ||
activeAppRecordId.value = data.activeAppRecordId | ||
}) | ||
|
||
onDevToolsStateUpdated((data) => { | ||
appRecords.value = data.appRecords | ||
activeAppRecordId.value = data.activeAppRecordId | ||
}) | ||
|
||
return { | ||
appRecords, | ||
activeAppRecord, | ||
} | ||
} | ||
|
||
export function setupVueDevTools() { | ||
const state = useDevToolsFrameState() | ||
|
||
const isInPopup = window.__NUXT_DEVTOOLS_IS_POPUP__ | ||
|
||
watchEffect(() => { | ||
if (isInPopup) | ||
toggleHighPerfMode(false) | ||
|
||
else | ||
toggleHighPerfMode(!state.value?.open) | ||
}) | ||
|
||
initDevToolsSeparateWindow({ | ||
onConnected(channel) { | ||
const bridge = initDevToolsSeparateWindowBridge(channel) | ||
setupDevToolsBridge(bridge) | ||
new HandShakeServer(bridge).onnConnect().then(() => { | ||
bridge.emit('devtools:client-ready') | ||
initVueDevToolsState() | ||
}) | ||
bridge.on('disconnect', () => { | ||
channel.close() | ||
initDevToolsSeparateWindow() | ||
}) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { addVitePlugin } from '@nuxt/kit' | ||
import { join } from 'pathe' | ||
import type { NuxtDevtoolsServerContext } from '../types' | ||
import { runtimeDir } from '../dirs' | ||
|
||
export function setup({ nuxt }: NuxtDevtoolsServerContext) { | ||
if (!nuxt.options.dev || nuxt.options.test) | ||
return | ||
|
||
addVitePlugin({ | ||
name: 'vue:devtools', | ||
async resolveId(importee: string) { | ||
if (importee.startsWith('virtual:vue-devtools-path:')) { | ||
const resolved = importee.replace('virtual:vue-devtools-path:', join(runtimeDir, 'vue-devtools/')) | ||
return resolved | ||
} | ||
}, | ||
transform(code, id) { | ||
const [filename] = id.split('?', 2) | ||
const appendTo = /\/entry\.m?js$/ | ||
|
||
if (appendTo.test(filename)) | ||
code = `import 'virtual:vue-devtools-path:overlay.js';\n${code}` | ||
|
||
return code | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { devtools } from '@vue/devtools-kit' | ||
import { initAppSeparateWindow } from '@vue/devtools-core' | ||
|
||
devtools.init() | ||
|
||
initAppSeparateWindow() |
Oops, something went wrong.