-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
39 lines (37 loc) · 2.02 KB
/
Copy pathvite.config.ts
File metadata and controls
39 lines (37 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { defineConfig, type Plugin } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
// Trim Fontsource's per-weight CSS at build time so only what the app renders ships.
// Fontsource's weight files carry EVERY subset plus a legacy `woff` fallback; per DESIGN.md
// §6 ("latin-subset, keep the bundle small") we keep only the latin + latin-ext subsets
// (latin-ext is where the peso sign ₱ / U+20B1 lives) and drop the woff — leaving woff2 with
// its unicode-range intact, which is Fontsource's own recommended model (and woff support is
// slated to be dropped upstream, fontsource/fontsource#1068). Running `enforce: 'pre'` means
// Vite sees the trimmed CSS before it resolves url()s, so the dropped files are never emitted.
function trimFontsource(): Plugin {
return {
name: 'trim-fontsource',
enforce: 'pre',
transform(code, id) {
if (!id.includes('@fontsource') || !id.endsWith('.css')) return null
// Drop every @font-face whose subset comment isn't latin/latin-ext.
let out = code.replace(
/\/\*\s*([^*]+?)\s*\*\/\s*@font-face\s*\{[^}]*\}\s*/g,
(block, label: string) => (/latin/.test(label) ? block : ''),
)
// Drop the legacy woff fallback from the surviving src lists (woff2 kept).
out = out.replace(/,\s*url\([^)]+\)\s*format\((['"])woff\1\)/g, '')
return out !== code ? { code: out, map: null } : null
},
}
}
// https://vite.dev/config/
export default defineConfig(({ mode }) => ({
// The one build serves two targets, which need different roots:
// · native (Capacitor) + dev: served from the WebView / dev-server root → '/'
// · web (GitHub Pages project site friendsnone.github.io/ledger/) → '/ledger/'
// `npm run build` (used by cap:sync) takes the default '/'; `npm run build:web`
// passes --mode web for the Pages deploy. Nav is in-memory tab state (no router),
// so a single index.html at either root is all that is needed.
base: mode === 'web' ? '/ledger/' : '/',
plugins: [trimFontsource(), svelte()],
}))