Skip to content

Commit

Permalink
Allow AlterFilePostBuildPlugin to work with dev-server
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Pow committed Aug 18, 2024
1 parent 28a34f7 commit a47575f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion config/webpack/AlterFilePostBuildPlugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
}

Expand Down

0 comments on commit a47575f

Please sign in to comment.