Twitter widget library provides twttr global variable. I would like to modulate this library on the fly using webpack with export-loader. The problem is that although the twttr variable twttr immediately displayed, its properties are still undefined when accessed synchronously.
console.log(twttr.widgets); // undefined setTimeout(function() { console.log(twttr); // now defined });
So var twttr = require('exports?twttr!./path/to/twitter') will return an object that is actually not ready for use.
While Twitter docs say that this is only necessary when loading the library asynchronously, I doubt that widget functions can be used if they are not packaged in twttr.ready .
At the very least, the web package offers a more convenient way to download the library and access twttr . I suspect that the odd behavior is due to this script coming from a time when there were no module systems, and SRP was ignored. However, I am very curious what the developers did in order to trigger this behavior, and my attempt to read the improved, reduced source code proved crazy.
source share