import react from '@vitejs/plugin-react-swc'
import {defineConfig, type UserConfig} from 'vite'
import obfuscatorPlugin from 'vite-plugin-javascript-obfuscator'
// @ts-ignore
import packageJson from './package.json'

// https://vite.dev/config/
export default defineConfig(({mode}) => {
  let config: UserConfig = {
    define: {
      __APP_VERSION__: JSON.stringify(packageJson.version) ?? '0.0.0',
    },
    plugins: [
      react(),
      obfuscatorPlugin({
        apply: config => config['mode'] === 'production',
        options: {
          compact: true,
          controlFlowFlattening: true,
          controlFlowFlatteningThreshold: 0.75,
          deadCodeInjection: true,
          deadCodeInjectionThreshold: 0.4,
          debugProtection: false,
          disableConsoleOutput: true,
          identifierNamesGenerator: 'hexadecimal',
          renameGlobals: false,
          stringArrayRotate: true,
          selfDefending: true,
          stringArray: true,
          stringArrayEncoding: ['base64'],
          stringArrayThreshold: 0.75,
          transformObjectKeys: true,
          unicodeEscapeSequence: false,
        },
      }),
    ],
  }
  return config
})
