【发布时间】:2016-12-21 23:28:27
【问题描述】:
我正在使用 webpack 来捆绑我的 JavaScript。我依赖于使用 any-promise 的模块,例如 popsicle。
这是我的代码:
var popsicle = require('popsicle');
popsicle.get('/').then(function() {
console.log('loaded URL');
});
这在Promise 可用但IE 11 does not provide Promise 的浏览器中运行良好。所以我想用es6-promise 作为一个polyfill。
我尝试将明确的ProvidePlugin 添加到我的webpack.config.js:
plugins: [
new webpack.ProvidePlugin({
'Promise': 'exports?global.Promise!es6-promise'
})
]
但我仍然在 IE 11 中遇到错误:any-promise browser requires a polyfill or explicit registration e.g: require('any-promise/register/bluebird')。
我尝试显式附加一个全局:
global.Promise = global.Promise || require('es6-promise');
但是 IE 11 给出了不同的错误:Object doesn't support this action。
我也尝试过显式注册 es6-promise:
require('any-promise/register/es6-promise');
var popsicle = require('popsicle');
这可行,但我必须在加载popsicle 的每个文件中执行此操作。我只想将Promise 附加到window。
如何确保始终使用 webpack 定义 window.Promise?
【问题讨论】:
标签: javascript webpack internet-explorer-11 polyfills