From a47575f362b2658a5a50602250fe721d9faea37c Mon Sep 17 00:00:00 2001 From: D-Pow Date: Sat, 17 Aug 2024 21:48:12 -0400 Subject: [PATCH] Allow AlterFilePostBuildPlugin to work with dev-server --- config/webpack/AlterFilePostBuildPlugin.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/webpack/AlterFilePostBuildPlugin.mjs b/config/webpack/AlterFilePostBuildPlugin.mjs index e2c68884..43f85181 100644 --- a/config/webpack/AlterFilePostBuildPlugin.mjs +++ b/config/webpack/AlterFilePostBuildPlugin.mjs @@ -155,10 +155,16 @@ class AlterFilePostBuildPlugin { replaceTextInFileBeforeEmit(compilation, origSrcFileName, oldText, newText) { const fileToModify = compilation.getAsset(origSrcFileName); + let fileContents = fileToModify.source.source(); + + if (typeof fileContents !== typeof '') { + // File contents is an ArrayBuffer when using dev-server + fileContents = new TextDecoder().decode(fileContents); + } compilation.updateAsset( origSrcFileName, - new sources.RawSource(fileToModify.source.source().replace(oldText, newText)), + new sources.RawSource(fileContents.replace(oldText, newText)), ); }