有谁知道如何在 gatsby 中集成 whatwg-fetch
fetch polyfill?
到目前为止,我所做的是 import 'whatwg-fetch';
在 gatsby-browser.js
中。现在我不确定如何将它作为第一个元素添加到 webpack 的 entry
属性中,大概是在 gatsby-node.js
中。
最佳答案
是的,这是我的(经过测试和工作的)gatsby-browser.js
的副本:
import 'whatwg-fetch' // require('whatwg-fetch') // if it's gatsby v2 - https://gatsby.app/no-mixed-modules
exports.onClientEntry = () => {
// Don't need to do anything here, but if you don't
// export something, the import won't work.
}
无需在 gatsby-node.js
中将 whatwg-fetch
添加到 webpack 的 entry
属性。
whatwg-fetch
也依赖于 Promise,但是 Promise
是 already polyfilled in gatsby ,因此无需为 Promise
添加额外的 polyfill。
关于reactjs - 如何在 Gatsby 中集成 whatwg-fetch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50302438/