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']
    },
    rollupOptions: {
      external: ['@apigo.cc/state', '@apigo.cc/bootstrap'],
      output: [
        {
          format: 'umd',
          name: 'ApigoBase',
          entryFileNames: 'base.js',
          extend: true,
          globals: {
            '@apigo.cc/state': 'ApigoState',
            '@apigo.cc/bootstrap': 'bootstrap'
          }
        },
        {
          format: 'umd',
          name: 'ApigoBase',
          entryFileNames: 'base.min.js',
          extend: true,
          globals: {
            '@apigo.cc/state': 'ApigoState',
            '@apigo.cc/bootstrap': 'bootstrap'
          },
          plugins: [terser()]
        }
      ]
    },
    minify: false
  }
});
