import process from 'node:process';

export default function vitePluginAxiosPlugin(): any {
  return {
    name: 'vite-plugin-axios-uni-plugin',
    transform(code: any, id: any) {
      if (process.env.UNI_PLATFORM?.includes('mp')) {
        if (id.includes('.ts')) {
          return {
            code: code.replaceAll('new URL', 'new globalThis.URL').replaceAll('new URLSearchParams', 'new globalThis.URLSearchParams'),
          };
        }
      }
    },
  };
}
