import { fileURLToPath, URL } from "url";

import vue from "@vitejs/plugin-vue";
import { defineConfig, loadEnv } from "vite";
// import vueI18n from '@intlify/vite-plugin-vue-i18n'
import alias from "@rollup/plugin-alias";

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
  return {
    plugins: [
      vue({
        template: {
          compilerOptions: {
            // treat all tags which start with '<it-' as custom elements
            isCustomElement: (tag) => tag.startsWith("it-"),
          },
        },
      }),
      // vueI18n({
      //   include: path.resolve(__dirname, './locales/**')
      // }),
      // won't work in vite's resolve.alias, so we'll make the alias here

      alias({
        // TODO: why is that used?
        // entries: [
        //   {
        //     find: 'vue-i18n',
        //     replacement: path.resolve(__dirname, './node_modules/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js')
        //   }
        // ]
      }),
    ],
    define: {
      __VUE_I18N_FULL_INSTALL__: true,
      __VUE_I18N_LEGACY_API__: false,
      __INTLIFY_PROD_DEVTOOLS__: false,
    },
    server: {
      port: 5173,
      hmr: { port: 5173 },
    },
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    build: {
      assetsDir: "static/vue",
    },
    test: {
      globals: true,
      environment: "jsdom",
    },
  };
});
