import { defineConfig } from 'vite';
import { resolve } from 'path';
import terser from '@rollup/plugin-terser';

export default defineConfig({
  resolve: {
    alias: {
      '@apigo.cc/state': resolve(__dirname, '../state/src/index.js'),
      '@apigo.cc/bootstrap': resolve(__dirname, '../bootstrap/src/index.js'),
      '@apigo.cc/base': resolve(__dirname, 'src/index.js')
    }
  },
  server: {
    fs: {
      allow: ['..']
    }
  },
  build: {
    lib: {
      entry: resolve(__dirname, 'src/index.js'),
      name: 'ApigoBase',
      formats: ['umd', 'es']
    },
    rollupOptions: {
      external: ['@apigo.cc/state', '@apigo.cc/bootstrap'],
      output: [
        {
          format: 'umd',
          name: 'ApigoBase',
          entryFileNames: 'base.js',
          globals: {
            '@apigo.cc/state': 'ApigoState',
            '@apigo.cc/bootstrap': 'bootstrap'
          }
        },
        {
          format: 'umd',
          name: 'ApigoBase',
          entryFileNames: 'base.min.js',
          globals: {
            '@apigo.cc/state': 'ApigoState',
            '@apigo.cc/bootstrap': 'bootstrap'
          },
          plugins: [terser()]
        },
        {
          format: 'es',
          entryFileNames: 'base.mjs'
        },
        {
          format: 'es',
          entryFileNames: 'base.min.mjs',
          plugins: [terser()]
        }
      ]
    },
    minify: false
  }
});
