import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import path from 'node:path'; import fs from 'node:fs'; import { fileURLToPath } from 'node:url'; const here = path.dirname(fileURLToPath(import.meta.url)); // pdf.js needs font data to draw pdfs which do not embed their fonts (and CMaps for // Korean/Chinese/Japanese text). Without it rendering such a pdf takes very long. // The files are only fetched when a pdf is selected, and only the ones that are needed. const pdfAssets = () => ({ name: 'pdfjs-assets', apply: 'build', closeBundle() { const out = path.resolve(here, '../public/app'); for (const dir of ['standard_fonts', 'cmaps']) { fs.cpSync(path.resolve(here, 'node_modules/pdfjs-dist', dir), path.join(out, dir), { recursive: true }); } }, }); // The server renders a thin html shell (public/pug/page.pug) which loads // app/main.js and app/main.css. Fixed file names keep that shell independent // of the build; heavy parts (pdf.js) are separate chunks loaded on demand. export default defineConfig({ base: './', plugins: [vue(), pdfAssets()], build: { outDir: path.resolve(here, '../public/app'), emptyOutDir: true, cssCodeSplit: false, target: 'es2022', rollupOptions: { input: path.resolve(here, 'src/main.js'), output: { entryFileNames: 'main.js', chunkFileNames: 'chunks/[name]-[hash].js', assetFileNames: (info) => { const name = (info.names && info.names[0]) || info.name || ''; return name.endsWith('.css') ? 'main.css' : 'assets/[name]-[hash][extname]'; }, }, }, chunkSizeWarningLimit: 1500, }, });