Skip to content

Commit

Permalink
Fix pdf previews
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak committed Aug 22, 2024
1 parent a34d9e3 commit 560371e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
22 changes: 21 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@
"uuid": "^10.0.0",
"vite": "^5.2.11",
"vite-plugin-checker": "^0.6.4",
"vite-plugin-pwa": "^0.20.0"
"vite-plugin-pwa": "^0.20.0",
"vite-plugin-static-copy": "^1.0.6"
},
"browserslist": {
"production": [
Expand Down
21 changes: 0 additions & 21 deletions public/pdf.worker.min.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/Components/Common/PDFViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function PDFViewer(
onDocumentLoadSuccess: (numPages: number) => void;
}>,
) {
pdfjs.GlobalWorkerOptions.workerSrc = "/pdf.worker.min.js";
pdfjs.GlobalWorkerOptions.workerSrc = "/pdf.worker.min.mjs";

return (
<div className="flex flex-col items-center justify-center">
Expand Down
19 changes: 19 additions & 0 deletions vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import path from "node:path";
import { createRequire } from "node:module";
import { VitePWA } from "vite-plugin-pwa";
import react from "@vitejs/plugin-react-swc";
import checker from "vite-plugin-checker";
import { viteStaticCopy } from "vite-plugin-static-copy";
import { treeShakeCareIcons } from "./plugins/treeShakeCareIcons";

const pdfWorkerPath = path.join(
path.dirname(
createRequire(import.meta.url).resolve("pdfjs-dist/package.json"),
),
"build",
"pdf.worker.min.mjs",
);

const cdnUrls =
process.env.CARE_CDN_URL ??
[
Expand All @@ -15,6 +26,14 @@ const cdnUrls =
export default {
envPrefix: "REACT_",
plugins: [
viteStaticCopy({
targets: [
{
src: pdfWorkerPath,
dest: "",
},
],
}),
react(),
checker({ typescript: true }),
treeShakeCareIcons({
Expand Down

0 comments on commit 560371e

Please sign in to comment.