From d5e07696926f554894bb316df2e6a49e00983229 Mon Sep 17 00:00:00 2001 From: Eugene Date: Thu, 8 Aug 2024 12:39:29 +0300 Subject: [PATCH] fix: pdfjs import --- src/components/DrawPDFFields/index.tsx | 6 ++++-- src/utils/pdf.ts | 6 ++++-- vite.config.ts | 11 ++++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/components/DrawPDFFields/index.tsx b/src/components/DrawPDFFields/index.tsx index e7880e4..63eb9ee 100644 --- a/src/components/DrawPDFFields/index.tsx +++ b/src/components/DrawPDFFields/index.tsx @@ -36,8 +36,10 @@ import { import { truncate } from 'lodash' import { hexToNpub } from '../../utils' import { toPdfFiles } from '../../utils/pdf.ts' -PDFJS.GlobalWorkerOptions.workerSrc = - 'node_modules/pdfjs-dist/build/pdf.worker.mjs' +PDFJS.GlobalWorkerOptions.workerSrc = new URL( + 'pdfjs-dist/build/pdf.worker.mjs', + import.meta.url +).toString() interface Props { selectedFiles: File[] diff --git a/src/utils/pdf.ts b/src/utils/pdf.ts index 2263737..78bab85 100644 --- a/src/utils/pdf.ts +++ b/src/utils/pdf.ts @@ -3,8 +3,10 @@ import * as PDFJS from 'pdfjs-dist' import { PDFDocument } from 'pdf-lib' import { Mark } from '../types/mark.ts' -PDFJS.GlobalWorkerOptions.workerSrc = - 'node_modules/pdfjs-dist/build/pdf.worker.mjs' +PDFJS.GlobalWorkerOptions.workerSrc = new URL( + 'pdfjs-dist/build/pdf.worker.mjs', + import.meta.url +).toString() /** * Scale between the PDF page's natural size and rendered size diff --git a/vite.config.ts b/vite.config.ts index 3d09617..4275495 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,6 +5,15 @@ import tsconfigPaths from 'vite-tsconfig-paths' export default defineConfig({ plugins: [react(), tsconfigPaths()], build: { - target: 'ES2022' + target: 'ES2022', + rollupOptions: { + output: { + manualChunks(id) { + if (id.includes('pdfjs-dist/build/pdf.worker.mjs')) { + return 'pdf.worker' + } + } + } + } } }) -- 2.34.1