我在promise-polyfill
-
/* jshint node: true */
/* global Promise: false */
"use strict";
if ( typeof Promise === "undefined" ) {
module.exports = require('promise-polyfill');
} else {
module.exports = Promise;
}
然后我将它注入我的所有模块中:
new webpack.ProvidePlugin({
'Promise': 'require-promise',
})
我遇到了问题。 Promise
是一个空对象,而是原生Promise
或undefined
。我如何将上下文(window
或global
)传递给此模块?
生成的代码如下:
function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(Promise) {/*** IMPORTS FROM imports-loader ***/
(function() {
/* jshint node: true */
/* global Promise: false */
"use strict";
console.log(Promise);
if ( typeof Promise === "undefined" ) {
module.exports = __webpack_require__(59);
} else {
module.exports = Promise;
}
/*** EXPORTS FROM exports-loader ***/
module.exports = Promise;
}.call(window));
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(7)))
/***/ },
答案 0 :(得分:0)
修正:
new webpack.ProvidePlugin({
'Promise': 'imports?Promise=>window.Promise!require-promise',
})