简体   繁体   English

如何在webpack中正确填充URLSearchParams?

[英]How to properly polyfill URLSearchParams in webpack?

I have a project that uses fetch polyfill from isomorphic-fetch . 我有一个项目,它使用来自isomorphic-fetch fetch polyfill。 I would like to use URLSearchParams with it to submit POST data. 我想用URLSearchParams来提交POST数据。 For fetch to support URLSearchParams it first checks if it is available in global object. 对于fetch以支持URLSearchParams,它首先检查它是否在全局对象中可用。 I though to use this polyfill for it but I don't know how to properly import it in webpack, so that fetch notices that it is available. 我虽然使用这个 polyfill但我不知道如何在webpack中正确导入它,以便fetch通知它是可用的。

How can I accomplish this? 我怎么能做到这一点? Thank you! 谢谢!

I had the same issue, had to switch to other polyfill to make it work, try this: 我有同样的问题,不得不切换到其他polyfill使其工作,试试这个:

https://github.com/jerrybendy/url-search-params-polyfill https://github.com/jerrybendy/url-search-params-polyfill

then simply add it to your webpack config: 然后只需将其添加到您的webpack配置:

entry: {
  bundle: [
    ...
    'url-search-params-polyfill',
    './src/entry'
  ]
}

How to include the WebReflection/url-search-params polyfill into webpack bundle: 如何将WebReflection/url-search-params包含到webpack包中:

entry: [
  'url-search-params/build/url-search-params.max',
  ...otherPolyfills,
  './your.entrypoint.jsx',
],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM