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/base': resolve(__dirname, '../base/src/index.js'),
      '@apigo.cc/editor': resolve(__dirname, 'src/index.js')
    }
  },
  build: {
    lib: {
      entry: resolve(__dirname, 'src/index.js'),
      name: 'ApigoEditor',
      formats: ['umd']
    },
    rollupOptions: {
      external: ['@apigo.cc/state', '@apigo.cc/base'],
      output: [
        {
          format: 'umd',
          name: 'ApigoEditor',
          entryFileNames: 'editor.js',
          globals: {
            '@apigo.cc/state': 'ApigoState',
            '@apigo.cc/base': 'ApigoBase'
          }
        },
        {
          format: 'umd',
          name: 'ApigoEditor',
          entryFileNames: 'editor.min.js',
          globals: {
            '@apigo.cc/state': 'ApigoState',
            '@apigo.cc/base': 'ApigoBase'
          },
          plugins: [terser()]
        }
      ]
    },
    minify: false
  }
});
