import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import tailwindcss from '@tailwindcss/vite'
import { viteSingleFile } from 'vite-plugin-singlefile'
import { readFileSync } from 'fs'
import { resolve } from 'path'

const version = JSON.parse(readFileSync(resolve(__dirname, 'version.json'), 'utf8'));
const versionString = `${version.major}.${version.minor}.${version.revision}`;

// https://vite.dev/config/
export default defineConfig({
  define: {
    __APP_VERSION__: JSON.stringify(versionString),
  },
  plugins: [
    svelte(),
    tailwindcss(),
    viteSingleFile({
      removeViteModuleLoader: true,
    }),
  ],
  // Resolve the W: subst drive to avoid path mismatches on Windows
  resolve: {
    preserveSymlinks: true,
  },
  build: {
    // Ensure everything goes into a single chunk
    cssCodeSplit: false,
    assetsInlineLimit: 100000,
  },
})
