2023-01-22 00:13:42 +00:00
|
|
|
import { sveltekit } from '@sveltejs/kit/vite';
|
2024-01-16 16:46:31 +00:00
|
|
|
import { paraglide } from '@inlang/paraglide-js-adapter-vite';
|
2023-12-09 00:02:30 +00:00
|
|
|
import fs from 'fs';
|
2023-01-22 00:13:42 +00:00
|
|
|
import type { UserConfig } from 'vite';
|
2023-04-09 20:44:45 +00:00
|
|
|
import { imagetools } from '@zerodevx/svelte-img/vite';
|
2023-01-22 00:13:42 +00:00
|
|
|
|
|
|
|
|
const config: UserConfig = {
|
2023-04-09 20:44:45 +00:00
|
|
|
plugins: [
|
|
|
|
|
sveltekit(),
|
2024-01-16 16:46:31 +00:00
|
|
|
paraglide({
|
|
|
|
|
project: './project.inlang',
|
|
|
|
|
outdir: './src/paraglide'
|
|
|
|
|
}),
|
2023-04-09 20:44:45 +00:00
|
|
|
imagetools({
|
|
|
|
|
// By default, directives are `?width=480;1024;1920&format=avif;webp;jpg`
|
2023-09-27 04:40:49 +00:00
|
|
|
// Now we change it to generate 5 variants instead - `avif/jpg` formats at `640/1280` + LQIP (Now as:run)
|
|
|
|
|
profiles: {
|
|
|
|
|
run: new URLSearchParams('?w=300;480;640;1024;1920&format=avif;webp;jpg&as=run:64')
|
|
|
|
|
}
|
2023-12-09 00:02:30 +00:00
|
|
|
}),
|
|
|
|
|
rawFonts(['.ttf'])
|
2023-04-09 20:44:45 +00:00
|
|
|
],
|
2023-01-22 00:13:42 +00:00
|
|
|
test: {
|
|
|
|
|
include: ['src/**/*.{test,spec}.{js,ts}']
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-09 00:02:30 +00:00
|
|
|
function rawFonts(ext) {
|
|
|
|
|
return {
|
|
|
|
|
name: 'vite-plugin-raw-fonts',
|
|
|
|
|
resolveId(id) {
|
|
|
|
|
return ext.some((e) => id.endsWith(e)) ? id : null;
|
|
|
|
|
},
|
|
|
|
|
transform(code, id) {
|
|
|
|
|
if (ext.some((e) => id.endsWith(e))) {
|
|
|
|
|
const buffer = fs.readFileSync(id);
|
|
|
|
|
return { code: `export default ${JSON.stringify(buffer)}`, map: null };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-22 00:13:42 +00:00
|
|
|
export default config;
|