import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
import rollupNodePolyFill from 'rollup-plugin-node-polyfills';
import wasm from 'vite-plugin-wasm';
import path from 'node:path';

export default defineConfig({
    resolve: {
        alias: {
            '@core': path.resolve(__dirname, '../../packages/core'),
        }
    },
    plugins: [sveltekit(), wasm()],
    test: {
        include: ['src/**/*.{test,spec}.{js,ts}']
    },
    preview: {
        port: 4173,
    },
    optimizeDeps: {
        esbuildOptions: {
            define: {
                global: 'globalThis'
            },
            plugins: [
                NodeGlobalsPolyfillPlugin({
                    buffer: true
                })
            ]
        }
    },
    build: {
        rollupOptions: {
            plugins: [rollupNodePolyFill()]
        }
    },
    server: {
        fs: {
            allow: ['./package.json']
        }
    }
});
