From 0ba806866a805859bdf0e2802a8af70cbe868e78 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Sat, 13 Mar 2021 18:36:27 +0100 Subject: [PATCH] Improve main entry detection logic Instead of manually parsing the HTML we rely on the resolveId hook which tells us who imported the current file. Didn't know about that before. This is much nicer! --- src/devtools.ts | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/devtools.ts b/src/devtools.ts index 8f9c2c8..5c42e68 100644 --- a/src/devtools.ts +++ b/src/devtools.ts @@ -13,30 +13,38 @@ export function preactDevtoolsPlugin({ let entry = ""; let config: ResolvedConfig; + let found = false; const plugin: Plugin = { name: "preact:devtools", + // Ensure that we resolve before everything else + enforce: "pre", + configResolved(resolvedConfig) { config = resolvedConfig; }, - transformIndexHtml(html) { - // Use this to grab the initial entry js file to - // inject "preact/debug" into at a later stage. - const match = html.match(/