OpenTalon / website · opentalon.ai / vite.config.js
| 1 | import { readFileSync } from 'node:fs' |
| 2 | import { basename } from 'node:path' |
| 3 | import { defineConfig } from 'vite' |
| 4 | |
| 5 | const siteHeaderFile = new URL('./src/site-header.html', import.meta.url) |
| 6 | |
| 7 | // Keep fonts as separate files. Vite inlines small assets as data: URLs, and the |
| 8 | // site's Content-Security-Policy (font-src 'self') blocks data: fonts. |
| 9 | export default defineConfig({ |
| 10 | plugins: [{ |
| 11 | name: 'opentalon-site-header', |
| 12 | transformIndexHtml: { |
| 13 | order: 'pre', |
| 14 | handler(html, { filename }) { |
| 15 | const page = basename(filename, '.html') |
| 16 | const href = `href="/${page}"` |
| 17 | const header = readFileSync(siteHeaderFile, 'utf8').trimEnd() |
| 18 | .replace(href, `${href} aria-current="page"`) |
| 19 | return html.replace(/^ {6}<!-- site-header -->$/m, header) |
| 20 | }, |
| 21 | }, |
| 22 | }], |
| 23 | build: { |
| 24 | rolldownOptions: { |
| 25 | input: ['index.html', 'download.html', 'help.html', 'compare.html', 'privacy.html', 'app-notices.html', 'research.html', 'start/index.html', '404.html'], |
| 26 | }, |
| 27 | assetsInlineLimit: (file) => (/\.(woff2?|ttf|otf)$/i.test(file) ? false : undefined), |
| 28 | }, |
| 29 | }) |