@@ -33,6 +33,10 @@ export function svelteInspector(options) {
3333 apply : 'serve' ,
3434 enforce : 'pre' ,
3535
36+ applyToEnvironment ( env ) {
37+ return env . config . consumer === 'client' ;
38+ } ,
39+
3640 configResolved ( config ) {
3741 viteConfig = config ;
3842 const environmentOptions = parseEnvironmentOptions ( config ) ;
@@ -43,7 +47,7 @@ export function svelteInspector(options) {
4347 }
4448
4549 // Handle config from svelte.config.js through vite-plugin-svelte
46- const vps = config . plugins . find ( ( p ) => p . name === 'vite-plugin-svelte' ) ;
50+ const vps = config . plugins . find ( ( p ) => p . name === 'vite-plugin-svelte:config ' ) ;
4751 const configFileOptions = vps ?. api ?. options ?. inspector ;
4852
4953 // vite-plugin-svelte can only pass options through it's `api` instead of `options`.
@@ -69,42 +73,53 @@ export function svelteInspector(options) {
6973 base : config . base ?. replace ( / \/ $ / , '' ) || ''
7074 } ;
7175 } ,
72-
73- async resolveId ( importee , _ , options ) {
74- if ( options ?. ssr || disabled ) {
75- return ;
76- }
77- if ( importee . startsWith ( 'virtual:svelte-inspector-options' ) ) {
78- return importee ;
79- } else if ( importee . startsWith ( 'virtual:svelte-inspector-path:' ) ) {
80- return importee . replace ( 'virtual:svelte-inspector-path:' , inspectorPath ) ;
76+ resolveId : {
77+ filter : {
78+ id : / ^ v i r t u a l : s v e l t e - i n s p e c t o r - /
79+ } ,
80+ async handler ( importee , _ , options ) {
81+ if ( options ?. ssr || disabled ) {
82+ return ;
83+ }
84+ if ( importee . startsWith ( 'virtual:svelte-inspector-options' ) ) {
85+ return importee ;
86+ } else if ( importee . startsWith ( 'virtual:svelte-inspector-path:' ) ) {
87+ return importee . replace ( 'virtual:svelte-inspector-path:' , inspectorPath ) ;
88+ }
8189 }
8290 } ,
83-
84- async load ( id , options ) {
85- if ( options ?. ssr || disabled ) {
86- return ;
87- }
88- if ( id === 'virtual:svelte-inspector-options' ) {
89- return `export default ${ JSON . stringify ( inspectorOptions ?? { } ) } ` ;
90- } else if ( id . startsWith ( inspectorPath ) ) {
91- // read file ourselves to avoid getting shut out by vites fs.allow check
92- const file = cleanUrl ( id ) ;
93- if ( fs . existsSync ( id ) ) {
94- return await fs . promises . readFile ( file , 'utf-8' ) ;
95- } else {
96- viteConfig . logger . error (
97- `[vite-plugin-svelte-inspector] failed to find svelte-inspector: ${ id } `
98- ) ;
91+ load : {
92+ filter : {
93+ id : {
94+ include : [ `${ inspectorPath } /**` , / ^ v i r t u a l : s v e l t e - i n s p e c t o r - o p t i o n s $ / ] ,
95+ exclude : [ / s t y l e & l a n g \. c s s $ / ]
96+ }
97+ } ,
98+ async handler ( id ) {
99+ if ( disabled ) {
100+ return ;
101+ }
102+ if ( id === 'virtual:svelte-inspector-options' ) {
103+ return `export default ${ JSON . stringify ( inspectorOptions ?? { } ) } ` ;
104+ } else if ( id . startsWith ( inspectorPath ) ) {
105+ // read file ourselves to avoid getting shut out by vites fs.allow check
106+ const file = cleanUrl ( id ) ;
107+ if ( fs . existsSync ( id ) ) {
108+ return await fs . promises . readFile ( file , 'utf-8' ) ;
109+ } else {
110+ viteConfig . logger . error (
111+ `[vite-plugin-svelte-inspector] failed to find svelte-inspector: ${ id } `
112+ ) ;
113+ }
99114 }
100115 }
101116 } ,
102-
103- transform ( code , id , options ) {
104- if ( options ?. ssr || disabled ) {
105- return ;
106- }
107- if ( id . includes ( 'vite/dist/client/client.mjs' ) ) {
117+ transform : {
118+ filter : { id : / v i t e \/ d i s t \/ c l i e n t \/ c l i e n t \. m j s (?: \? | $ ) / } ,
119+ handler ( code ) {
120+ if ( disabled ) {
121+ return ;
122+ }
108123 return { code : `${ code } \nimport('virtual:svelte-inspector-path:load-inspector.js')` } ;
109124 }
110125 }
0 commit comments