Skip to content

Commit caf21f8

Browse files
committed
✨ feat: Enable debuging on all HTML pages
1 parent b43ef4f commit caf21f8

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

rollup.config.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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*<script src="\.\.\/debug\/debug\.bundle\.js"><\/script>\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
153198
const 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

Comments
 (0)