Alias and dedupe pdfjs-dist so GlobalWorkerOptions.workerSrc set in main.tsx reaches getDocument in the linked evidence-source package; allow sibling fs roots.
69 lines
2.7 KiB
TypeScript
69 lines
2.7 KiB
TypeScript
import { defineConfig } from "vite";
|
|
import react from "@vitejs/plugin-react";
|
|
import { viteStaticCopy } from "vite-plugin-static-copy";
|
|
import { fileURLToPath } from "node:url";
|
|
import { dirname, resolve } from "node:path";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
export default defineConfig({
|
|
plugins: [
|
|
react(),
|
|
// PDF.js needs its cmaps (character maps for CID fonts) and
|
|
// standard fonts (Helvetica/Times/Courier metrics) to position
|
|
// text-layer spans correctly. Without them, PDFs with embedded
|
|
// CID fonts or unembedded standard fonts get rendered to canvas
|
|
// OK but their textLayer overlays land in the wrong place — text
|
|
// appears unselectable or selection jumps to a different region.
|
|
// We serve both directories straight from `node_modules/pdfjs-dist`.
|
|
viteStaticCopy({
|
|
targets: [
|
|
{
|
|
src: resolve(__dirname, "node_modules/pdfjs-dist/cmaps") + "/[!.]*",
|
|
dest: "cmaps",
|
|
},
|
|
{
|
|
src: resolve(__dirname, "node_modules/pdfjs-dist/standard_fonts") + "/[!.]*",
|
|
dest: "standard_fonts",
|
|
},
|
|
],
|
|
}),
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
"@shared": resolve(__dirname, "../citation-engine/src/shared"),
|
|
"@engine": resolve(__dirname, "../citation-engine/src/engine"),
|
|
"@source": resolve(__dirname, "src/source"),
|
|
"@binder": resolve(__dirname, "../evidence-binder/src"),
|
|
"@work": resolve(__dirname, "../citation-work/src/work"),
|
|
"@app": resolve(__dirname, "src/app"),
|
|
// Force a single pdfjs-dist instance across the umbrella and linked
|
|
// packages (evidence-source, citation-work, …). Each sibling has its
|
|
// own node_modules/pdfjs-dist path; without this alias Vite loads two
|
|
// module graphs, so main.tsx's GlobalWorkerOptions.workerSrc never
|
|
// reaches getDocument() inside evidence-source — upload fails with
|
|
// 'No "GlobalWorkerOptions.workerSrc" specified.'
|
|
"pdfjs-dist": resolve(__dirname, "node_modules/pdfjs-dist"),
|
|
},
|
|
// Belt-and-braces for the same dual-instance problem (React too).
|
|
dedupe: ["pdfjs-dist", "react", "react-dom"],
|
|
},
|
|
server: {
|
|
fs: {
|
|
// Allow Vite to serve /fixtures/pdfs/*.pdf from the project root,
|
|
// and to read linked sibling packages outside this repo root.
|
|
allow: [
|
|
resolve(__dirname),
|
|
resolve(__dirname, "../citation-engine"),
|
|
resolve(__dirname, "../evidence-source"),
|
|
resolve(__dirname, "../evidence-anchor"),
|
|
resolve(__dirname, "../evidence-binder"),
|
|
resolve(__dirname, "../citation-work"),
|
|
],
|
|
},
|
|
},
|
|
optimizeDeps: {
|
|
// pdfjs-dist ships its worker as a .mjs Vite needs to handle.
|
|
exclude: ["pdfjs-dist"],
|
|
},
|
|
});
|