11import { ResolvedConfig , type Plugin } from 'vite' ;
22import { getServerFunctions } from './rpc' ;
33import { createServerRpc , setViteServerContext , VIRTUAL_QWIK_DEVTOOLS_KEY , INNER_USE_HOOK } from '@devtools/kit' ;
4- import _traverse from '@babel/traverse' ;
5- import _generate from '@babel/generator' ;
64import VueInspector from 'vite-plugin-inspect'
75import useCollectHooksSource from './utils/useCollectHooks'
86import { parseQwikCode } from './parse/parse' ;
@@ -15,13 +13,28 @@ export function qwikDevtools(): Plugin[] {
1513 name : 'vite-plugin-qwik-devtools' ,
1614 apply : 'serve' ,
1715 resolveId ( id ) {
18- if ( id === VIRTUAL_QWIK_DEVTOOLS_KEY ) {
19- return id ;
16+ // Normalize to a stable, absolute-like id so Qwik can generate runtime chunks
17+ const clean = id . split ( '?' ) [ 0 ] . split ( '#' ) [ 0 ] ;
18+ if (
19+ clean === VIRTUAL_QWIK_DEVTOOLS_KEY ||
20+ clean === `/${ VIRTUAL_QWIK_DEVTOOLS_KEY } ` ||
21+ clean === `\u0000${ VIRTUAL_QWIK_DEVTOOLS_KEY } ` ||
22+ clean === `/@id/${ VIRTUAL_QWIK_DEVTOOLS_KEY } `
23+ ) {
24+ return `/${ VIRTUAL_QWIK_DEVTOOLS_KEY } ` ;
2025 }
2126 } ,
2227 load ( id ) {
23- if ( id === VIRTUAL_QWIK_DEVTOOLS_KEY ) {
24- return useCollectHooksSource ;
28+ if (
29+ id === `/${ VIRTUAL_QWIK_DEVTOOLS_KEY } ` ||
30+ id === VIRTUAL_QWIK_DEVTOOLS_KEY ||
31+ id === `\u0000${ VIRTUAL_QWIK_DEVTOOLS_KEY } ` ||
32+ id === `/@id/${ VIRTUAL_QWIK_DEVTOOLS_KEY } `
33+ ) {
34+ return {
35+ code : useCollectHooksSource ,
36+ map : null ,
37+ } ;
2538 }
2639 } ,
2740 configResolved ( viteConfig ) {
@@ -49,14 +62,11 @@ export function qwikDevtools(): Plugin[] {
4962 code = `import { QwikDevtools } from '${ importPath } ';\n${ code } ` ;
5063 }
5164
52- // Find the closing body tag and inject the QwikDevtools component before it
65+ // Find the closing body tag and append QwikDevtools at the end of body
5366 const match = code . match ( / < b o d y [ ^ > ] * > ( [ \s \S ] * ?) < \/ b o d y > / ) ;
5467 if ( match ) {
5568 const bodyContent = match [ 1 ] ;
56- const newBodyContent = bodyContent . replace (
57- / { ! i s D e v & & < S e r v i c e W o r k e r R e g i s t e r \/ > } / ,
58- `{!isDev && <ServiceWorkerRegister />}\n {isDev && <QwikDevtools />}` ,
59- ) ;
69+ const newBodyContent = `${ bodyContent } \n <QwikDevtools />` ;
6070 code = code . replace ( bodyContent , newBodyContent ) ;
6171 }
6272
0 commit comments