@@ -33,6 +33,10 @@ export function svelteInspector(options) {
33
33
apply : 'serve' ,
34
34
enforce : 'pre' ,
35
35
36
+ applyToEnvironment ( env ) {
37
+ return env . config . consumer === 'client' ;
38
+ } ,
39
+
36
40
configResolved ( config ) {
37
41
viteConfig = config ;
38
42
const environmentOptions = parseEnvironmentOptions ( config ) ;
@@ -43,7 +47,7 @@ export function svelteInspector(options) {
43
47
}
44
48
45
49
// 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 ' ) ;
47
51
const configFileOptions = vps ?. api ?. options ?. inspector ;
48
52
49
53
// vite-plugin-svelte can only pass options through it's `api` instead of `options`.
@@ -69,42 +73,53 @@ export function svelteInspector(options) {
69
73
base : config . base ?. replace ( / \/ $ / , '' ) || ''
70
74
} ;
71
75
} ,
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
+ }
81
89
}
82
90
} ,
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
+ }
99
114
}
100
115
}
101
116
} ,
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
+ }
108
123
return { code : `${ code } \nimport('virtual:svelte-inspector-path:load-inspector.js')` } ;
109
124
}
110
125
}
0 commit comments