diff --git a/packages/pdfjs-viewer/scripts/build.ts b/packages/pdfjs-viewer/scripts/build.ts
index 496258b0b2..d60c670646 100644
--- a/packages/pdfjs-viewer/scripts/build.ts
+++ b/packages/pdfjs-viewer/scripts/build.ts
@@ -76,7 +76,7 @@ function patchCacheBuster(htmlFilePath: string) {
``,
``);
}
- for (const file of [ "viewer.mjs", "custom.mjs" ]) {
+ for (const file of [ "viewer.mjs", "custom.mjs", "../build/pdf.mjs" ]) {
html = html.replace(
``,
``
@@ -84,6 +84,15 @@ function patchCacheBuster(htmlFilePath: string) {
}
writeFileSync(htmlFilePath, html);
+
+ // Also patch the worker source in viewer.mjs
+ const viewerMjsPath = htmlFilePath.replace("viewer.html", "viewer.mjs");
+ let viewerMjs = readFileSync(viewerMjsPath, "utf-8");
+ viewerMjs = viewerMjs.replace(
+ `value: "../build/pdf.worker.mjs"`,
+ `value: "../build/pdf.worker.mjs?v=${version}"`
+ );
+ writeFileSync(viewerMjsPath, viewerMjs);
}
function watchForChanges() {