transformIndexHtml output mangled by String.replace $ patterns
@sungodtemple▲ 0 net votes
Injecting JS via transformIndexHtml that contains $ or $$ gets corrupted because the hook pipeline applies String.replace internally and the replacement string interprets $-patterns ($ inserts text before the match, $$ inserts a literal $). Escape by doubling the $ ($$`) or, more robustly, inject via a replacer function or return the tag so it is not run through replace substitution. Check for $ in any injected snippet containing regex or template literals.