@@ -17,14 +17,15 @@ export function preactDevtoolsPlugin({
1717 devToolsEnabled,
1818 shouldTransform,
1919} : PreactDevtoolsPluginOptions ) : Plugin {
20+ const name = "preact:devtools" ;
2021 const log = debug ( "vite:preact-devtools" ) ;
2122
2223 let entry = "" ;
2324 let config : ResolvedConfig ;
2425 let found = false ;
2526
2627 const plugin : Plugin = {
27- name : "preact:devtools" ,
28+ name,
2829
2930 // Ensure that we resolve before everything else
3031 enforce : "pre" ,
@@ -41,6 +42,20 @@ export function preactDevtoolsPlugin({
4142 config = resolvedConfig ;
4243 devToolsEnabled =
4344 devToolsEnabled ?? ( ! config . isProduction || devtoolsInProd ) ;
45+
46+ // Whilst newer versions of Vite allow for hook filtering, we'd need to set the filter
47+ // after the fact as we can only read `config.isProduction` here. And if we're setting
48+ // the filter after the fact, well, we can just remove the plugin hooks entirely. Skips
49+ // filtering altogether.
50+ if ( ! devToolsEnabled ) {
51+ const devToolsPlugin = config . plugins . find (
52+ ( p : Plugin ) => p . name === name ,
53+ ) ;
54+ if ( devToolsPlugin ) {
55+ delete devToolsPlugin . resolveId ;
56+ delete devToolsPlugin . transform ;
57+ }
58+ }
4459 } ,
4560
4661 resolveId ( url , importer = "" ) {
@@ -62,7 +77,7 @@ export function preactDevtoolsPlugin({
6277 transform ( code , url ) {
6378 const { id } = parseId ( url ) ;
6479
65- if ( entry === id && ( ! config . isProduction || devToolsEnabled ) ) {
80+ if ( entry === id ) {
6681 const source = config . isProduction ? "preact/devtools" : "preact/debug" ;
6782 code = `import "${ source } ";\n${ code } ` ;
6883
0 commit comments