Answer the question
In order to leave comments, you need to log in
Webpack 2 how to polyfill a Promise asynchronously?
Let's say:
webpack.config.js
, new webpack.ProvidePlugin({
Promise: './bluebird-lazy.js'
})
exports default (function(w){
if('Promise' in w){
return w.Promise;
}else{
//return
import(bluebird).then(Promise => window.Promise); // вот тут и встает проблема асинхронности
}
})(window);
Answer the question
In order to leave comments, you need to log in
Write a loadPolyfills function that accepts a callback (because you can't be sure at the time of calling it that the promises are implemented), and move all the entry point code into this callback. For purity, you can move this action into a self-written loader or plugin, or maybe there are already similar ones. Technically, this is the only correct way.
In your case, the function might look like this:
exports default function loadPolyfills(callback) {
if (!window.Promise) {
require.ensure([], function () {
window.Promise = require('bluebird');
callback();
});
} else {
callback();
}
};
RewriteRule ^blog/articles/([a-z0-9\-/]+) http://site.ru/blog/article.php\?id=$1 [L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question