char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
e21152dc9
char/aliceai-t5-moe
1import { BUILD_CONFIG } from '../src/lib/constants/pwa.constants' ; 2import { existsSync , readFileSync , writeFileSync } from 'node:fs' ; 3import { resolve } from 'path' ; 4import type { Plugin } from 'vite' ; 5 6let processed = false ; 7 8const OUTPUT_DIR = process . env . LLAMA_UI_OUT_DIR ?? BUILD_CONFIG . OUTPUT_DIR ; 9 10function rewrite ( path :string , pairs :[ string , string ][]) :void { 11if ( ! existsSync ( path )) { 12return ; 13} 14 15const text = readFileSync ( path , 'utf-8' ); 16 17let out = text ; 18 19for ( const [ from , to ] of pairs ) { 20out = out . split ( from ). join ( to ); 21} 22 23if ( out !== text ) { 24writeFileSync ( path , out , 'utf-8' ); 25} 26} 27 28/** 29* Relativize SvelteKit absolute base refs so the build is relocatable under any subpath. 30* 31* SvelteKit bakes root absolute /_app/ paths into the SPA fallback because paths.relative 32* does not apply to a depth agnostic fallback page. Rewriting to ./_app/ lets a plain 33* recursive copy of the output into /any/subdir/ resolve assets against the document URL. 34* Runs after adapter-static writes index.html and the PWA plugin writes sw.js, deferred the 35* same way as buildInfoPlugin so the emitted files exist. 36*/ 37export function relativizeBasePlugin () :Plugin { 38return { 39apply :'build' , 40closeBundle () { 41setTimeout (() => { 42try { 43if ( processed ) return ; 44 45processed = true ; 46 47const outDir = resolve ( OUTPUT_DIR ); 48 49// index.html: modulepreload, stylesheet and bootstrap import reference "/_app/ 50rewrite ( resolve ( outDir , 'index.html' ), [[ '"/_app/' , '"./_app/' ]]); 51 52// sw.js: the only absolute entries are the navigate fallback precache key and handler 53rewrite ( resolve ( outDir , 'sw.js' ), [ 54[ '{url:"/"' , '{url:"./"' ], 55[ 'createHandlerBoundToURL("/"' , 'createHandlerBoundToURL("./"' ] 56]); 57 58console . log ( 'Relativized base refs in index.html and sw.js' ); 59} catch ( error ) { 60console . error ( 'Failed to relativize base refs:' , error ); 61} 62}, 100 ); 63}, 64name :'llamacpp:relativize-base' 65}; 66}