import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin, bytecodePlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import UnoCSS from 'unocss/vite'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AppLoading from 'vite-plugin-app-loading'

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin(), bytecodePlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin(), bytecodePlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        '@': resolve('src/renderer/src'),
        '~@': resolve('src/renderer/src')
      }
    },
    plugins: [
      vue(),
      (monacoEditorPlugin as any).default({
        languageWorkers: ['editorWorkerService', 'json'],
        customDistPath: (root: string) => {
          return `${root}/dist/monaco-editor`
        }
      }),
      // 自定引入插件
      AutoImport({
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      }),
      UnoCSS(),
      vueJsx(),
      AppLoading('src/renderer/loading.html')
    ]
  }
})
