import path from "node:path";
import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";
import { recipeSeoPlugin } from "./vite-plugin-recipe-seo";
import { cspPlugin } from "./vite-plugin-csp";
import { toOrigin } from "./vite-plugin-csp";

const pkg = (relative: string) => path.resolve(__dirname, relative);

const matomoOrigin = toOrigin(process.env.VITE_MATOMO_URL);

export default defineConfig({
  plugins: [cspPlugin({ matomoOrigin }), recipeSeoPlugin(), solidPlugin()],
  resolve: {
    alias: {
      "@ben-to/builder/domain": pkg("../../packages/features/builder/src/domain.ts"),
      "@ben-to/recipes/catalog": pkg("../../packages/features/recipes/src/catalog.ts"),
      "@ben-to/recipes/domain": pkg("../../packages/features/recipes/src/domain.ts"),
      "@ben-to/recipes/recipe-og-meta": pkg("../../packages/features/recipes/src/recipe-og-meta.ts"),
      "@ben-to/i18n/dictionary": pkg("../../packages/shared/i18n/src/dictionary.ts"),
      "@ben-to/testing/iso-date": pkg("../../packages/shared/testing/src/iso-date.ts"),
      "@ben-to/privacy/cookie-consent": pkg("../../packages/shared/privacy/src/cookie-consent.ts")
    }
  },
  server: {
    port: 3000
  }
});
