import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import litestar from "litestar-vite-plugin";
{% if use_tailwind %}
import tailwindcss from "@tailwindcss/vite";
{% endif %}

{% if enable_ssr %}
export default defineConfig(({ ssrBuild }) => ({
{% else %}
export default defineConfig({
{% endif %}
  server: {
    host: "0.0.0.0",
    port: Number(process.env.VITE_PORT || "{{ vite_port }}"),
    cors: true,
    hmr: {
      host: "localhost",
    },
  },
  plugins: [
{% if use_tailwind %}
    tailwindcss(),
{% endif %}
    vue(),
    litestar({
      input: ["{{ resource_dir }}/main.ts"],
{% if enable_ssr %}
      ssr: "{{ resource_dir }}/ssr.ts",
{% endif %}
{% if enable_types %}
      types: "auto",
{% endif %}
    }),
  ],
{% if enable_ssr %}
  build: {
    rollupOptions: {
      output: ssrBuild
        ? {
            entryFileNames: "ssr.js",
          }
        : undefined,
    },
  },
{% endif %}
  resolve: {
    alias: {
      "@": "/{{ resource_dir }}",
    },
  },
{% if enable_ssr %}
}));
{% else %}
});
{% endif %}
