diff --git a/package.json b/package.json index 6f918243..27cedf18 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "@docsearch/css": "^3.0.0", "@docsearch/js": "^3.0.0", "@vitejs/plugin-vue": "^2.3.2", + "@vue/devtools-api": "^6.1.4", "@vueuse/core": "^8.5.0", "body-scroll-lock": "^4.0.0-beta.0", "shiki": "^0.10.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 322d556f..a0cb63f7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,7 @@ importers: '@types/polka': ^0.5.3 '@types/prompts': ^2.0.14 '@vitejs/plugin-vue': ^2.3.2 + '@vue/devtools-api': ^6.1.4 '@vueuse/core': ^8.5.0 body-scroll-lock: ^4.0.0-beta.0 chokidar: ^3.5.1 @@ -74,6 +75,7 @@ importers: '@docsearch/css': 3.1.0 '@docsearch/js': 3.1.0 '@vitejs/plugin-vue': 2.3.3_vite@2.9.9+vue@3.2.33 + '@vue/devtools-api': 6.1.4 '@vueuse/core': 8.5.0_vue@3.2.33 body-scroll-lock: 4.0.0-beta.0 shiki: 0.10.1 @@ -722,6 +724,10 @@ packages: '@vue/shared': 3.2.33 dev: false + /@vue/devtools-api/6.1.4: + resolution: {integrity: sha512-IiA0SvDrJEgXvVxjNkHPFfDx6SXw0b/TUkqMcDZWNg9fnCAHbTpoo59YfJ9QLFkwa3raau5vSlRVzMSLDnfdtQ==} + dev: false + /@vue/reactivity-transform/3.2.33: resolution: {integrity: sha512-4UL5KOIvSQb254aqenW4q34qMXbfZcmEsV/yVidLUgvwYQQ/D21bGX3DlgPUGI3c4C+iOnNmDCkIxkILoX/Pyw==} dependencies: diff --git a/src/client/app/components/Debug.vue b/src/client/app/components/Debug.vue deleted file mode 100644 index 41e926a0..00000000 --- a/src/client/app/components/Debug.vue +++ /dev/null @@ -1,86 +0,0 @@ - - - - - diff --git a/src/client/app/devtools.ts b/src/client/app/devtools.ts new file mode 100644 index 00000000..05935e47 --- /dev/null +++ b/src/client/app/devtools.ts @@ -0,0 +1,41 @@ +import { setupDevtoolsPlugin } from '@vue/devtools-api' +import type { App } from 'vue' +import type { Router } from './router' +import type { VitePressData } from './data' + +const COMPONENT_STATE_TYPE = 'VitePress' + +export const setupDevtools = ( + app: App, + router: Router, + data: VitePressData +): void => { + setupDevtoolsPlugin( + { + // fix recursive reference + app: app as any, + id: 'org.vuejs.vitepress', + label: 'VitePress', + packageName: 'vitepress', + homepage: 'https://vitepress.vuejs.org', + componentStateTypes: [COMPONENT_STATE_TYPE] + }, + (api) => { + api.on.inspectComponent((payload) => { + payload.instanceData.state.push({ + type: COMPONENT_STATE_TYPE, + key: 'route', + value: router.route, + editable: false + }) + + payload.instanceData.state.push({ + type: COMPONENT_STATE_TYPE, + key: 'data', + value: data, + editable: false + }) + }) + } + ) +} diff --git a/src/client/app/index.ts b/src/client/app/index.ts index 2e8e88d6..b46ca673 100644 --- a/src/client/app/index.ts +++ b/src/client/app/index.ts @@ -2,7 +2,6 @@ import { App, createApp as createClientApp, createSSRApp, - defineAsyncComponent, h, onMounted, watch @@ -58,12 +57,6 @@ export function createApp() { // install global components app.component('Content', Content) app.component('ClientOnly', ClientOnly) - app.component( - 'Debug', - import.meta.env.PROD - ? () => null - : defineAsyncComponent(() => import('./components/Debug.vue')) - ) // expose $frontmatter Object.defineProperty(app.config.globalProperties, '$frontmatter', { @@ -80,6 +73,13 @@ export function createApp() { }) } + // setup devtools in dev mode + if (import.meta.env.DEV || __VUE_PROD_DEVTOOLS__) { + import('./devtools').then(({ setupDevtools }) => + setupDevtools(app, router, data) + ) + } + return { app, router, data } } diff --git a/src/client/index.ts b/src/client/index.ts index 96c628bf..a4e3fb18 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -24,6 +24,3 @@ export { inBrowser, withBase } from './app/utils' // components export { Content } from './app/components/Content' - -import _Debug from './app/components/Debug.vue' -export const Debug = _Debug as import('vue').ComponentOptions diff --git a/src/client/shim.d.ts b/src/client/shim.d.ts index 6a486e5d..868fc51e 100644 --- a/src/client/shim.d.ts +++ b/src/client/shim.d.ts @@ -1,6 +1,7 @@ declare const __VP_HASH_MAP__: Record declare const __ALGOLIA__: boolean declare const __CARBON__: boolean +declare const __VUE_PROD_DEVTOOLS__: boolean declare module '*.vue' { import { ComponentOptions } from 'vue'