@@ -149,6 +149,51 @@ const processCSS = (inputFiles, outputPath, minimize = true) => ({
149149 } ,
150150} ) ;
151151
152+ // Process static HTML files to conditionally inject debug scripts
153+ const processStaticHTML = ( ) => ( {
154+ name : "process-static-html" ,
155+ writeBundle ( ) {
156+ const htmlFiles = [
157+ {
158+ src : "src/options/options.html" ,
159+ debugScript : ' <script src="../debug/debug.bundle.js"></script>' ,
160+ insertBefore : "</body>" ,
161+ } ,
162+ {
163+ src : "src/fullMemory/fullMemory.html" ,
164+ debugScript : ' <script src="../debug/debug.bundle.js"></script>' ,
165+ insertBefore : "</head>" ,
166+ } ,
167+ {
168+ src : "src/bibMatcher/bibMatcher.html" ,
169+ debugScript : ' <script src="../debug/debug.bundle.js"></script>' ,
170+ insertBefore : "</body>" ,
171+ } ,
172+ ] ;
173+
174+ htmlFiles . forEach ( ( { src, debugScript, insertBefore } ) => {
175+ let htmlContent = fs . readFileSync ( src , "utf-8" ) ;
176+
177+ // Remove any existing debug script tags first (cleanup)
178+ htmlContent = htmlContent . replace (
179+ / \s * < s c r i p t s r c = " \. \. \/ d e b u g \/ d e b u g \. b u n d l e \. j s " > < \/ s c r i p t > \s * / g,
180+ ""
181+ ) ;
182+
183+ // Only inject debug script in development mode
184+ if ( isDevelopment ) {
185+ htmlContent = htmlContent . replace (
186+ insertBefore ,
187+ `${ debugScript } \n${ insertBefore } `
188+ ) ;
189+ }
190+
191+ // Write the processed HTML back
192+ fs . writeFileSync ( src , htmlContent ) ;
193+ } ) ;
194+ } ,
195+ } ) ;
196+
152197// Configuration for different builds
153198const configs = [
154199 // Theme JS (standalone)
@@ -258,7 +303,7 @@ const configs = [
258303 name : "PMDebug" ,
259304 sourcemap : true ,
260305 } ,
261- plugins : getCommonPlugins ( ) ,
306+ plugins : [ ... getCommonPlugins ( ) , processStaticHTML ( ) ] ,
262307 } ,
263308 ]
264309 : [ ] ) ,
0 commit comments