import requireTransform from 'vite-plugin-require-transform';
import Unocss from 'unocss/vite';
import vue from './vue';
import html from './html';
import visualizer from './visualizer';
import compress from './compress';
import lazyloadCom from './lazyloadCom';
import AutoImport from './autoImport';
import vueSetupExtend from 'unplugin-vue-setup-extend-plus/vite';

// import legacyPlugin from './legacy';
/**
 * vite插件
 * @param viteEnv - 环境变量配置
 */
export function setupVitePlugins(viteEnv) {
  const plugins = [
    ...vue,
    Unocss(),
    html(viteEnv),
    lazyloadCom,
    AutoImport,
    requireTransform({}),
    vueSetupExtend(),
  ];

  if (viteEnv.VITE_VISUALIZER === 'Y') {
    plugins.push(visualizer);
  }
  if (viteEnv.VITE_COMPRESS === 'Y') {
    plugins.push(compress(viteEnv));
  }

  return plugins;
}
