0
我有包裝器模塊在promise-polyfill
-如何通過ProvidePlugin設置提供模塊的上下文?
/* 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)))
/***/ },
究竟哪裏是你的問題? 'Promise'被拒絕爲'{}'? – Rohit416
是的。我使用生成的代碼 –
更新了答案,而'console.log(Promise)'輸出到....? – Rohit416