Search code examples
javascriptwebpackfetchpolyfills

Using whatwg-fetch with webpack


In the npm page for whatwg-fetch it says:

Importing will automatically polyfill window.fetch and related APIs:

import 'whatwg-fetch'

window.fetch(...)

Below that in the same section it says

For use with webpack, add this package in the entry configuration option before your application entry point:

entry: ['whatwg-fetch', ...]

I use webpack.

Should I both import it and add it as an entry, or is the entry enough?


Solution

  • One or the other, they will produce the same output anyways. I suggest importing in your entry point other than adding on the entry array on your webpack configuration.