tcollinsworth / axios-cached-dns-resolve

Uses async dns.resolve instead of synchronous dns.lookup, optional cache, and periodic background refreshing
MIT License
39 stars 32 forks source link

When use in electron/web isomorphic code,it need to introduce on demand #39

Closed Wonder233 closed 11 months ago

Wonder233 commented 11 months ago

hello, I built an electron and web isomorphic project, and I want to introduced as needed according to the current environment.

like follow:

import axios from 'axios'
const axiosIns= axios.create(config);

if (window.process && window.process.platform) {
  const dnsResolve = require('axios-cached-dns-resolve');
  dnsResolve.registerInterceptor(axiosIns);
}

axiosIns.get('xxx');

Can this usage be supported?

tcollinsworth commented 11 months ago

The library is ESM which use imports and not require. what you want to do is use something like:

const dnsResolve = await import('axios-cached-dns-resolve');
Wonder233 commented 11 months ago

Such usage will report an error: const dnsResolve = await import('axios-cached-dns-resolve'); image

The following are the changes while I forked to your repository. It support both esm and cjs. Can I make a PR? https://github.com/Wonder233/axios-cached-dns-resolve