mirror of
https://github.com/bartvdbraak/hellob.art.git
synced 2025-06-28 07:19:09 +00:00
feat: add vite build and transform step for base64 inlining
This commit is contained in:
parent
19971636d4
commit
ecc83f4a4f
2 changed files with 37 additions and 18 deletions
|
@ -4,9 +4,11 @@ import { defineConfig } from 'vite';
|
|||
import fs from 'fs';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [enhancedImages(), sveltekit(), rawFonts(['.woff'])],
|
||||
ssr: {
|
||||
noExternal: ['three']
|
||||
plugins: [enhancedImages(), sveltekit(), rawFonts(['.woff']), base64()],
|
||||
server: {
|
||||
fs: {
|
||||
allow: ['./']
|
||||
}
|
||||
},
|
||||
define: {
|
||||
'import.meta.env.VERCEL_URL': JSON.stringify(process.env.VERCEL_URL)
|
||||
|
@ -24,3 +26,19 @@ function rawFonts(ext: string[]) {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
function base64() {
|
||||
return {
|
||||
name: 'vite-plugin-base64-loader',
|
||||
transform(_code: string, id: string) {
|
||||
const [path, query] = id.split('?');
|
||||
|
||||
if (query !== 'base64') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const base64 = fs.readFileSync(path, { encoding: 'base64' });
|
||||
return { code: `export default ${JSON.stringify(base64)}`, map: null };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue