Reputation: 5877
I am currently using babel-polyfill
and webpack to construct a single page application.
However, I can't quite see how a simple import
statement allows for polyfilled functionality to be available in the rest of the code. My understanding of ES6 imports is still a bit fuzzy, so perhaps that's the issue.
If import 'babel-polyfill';
is only being used for side effects, how do these side effects make it into the importing file? Isn't the scope on the imported file out of reach?
Upvotes: 0
Views: 599
Reputation: 665456
If
import "babel-polyfill";
is only being used for side effects, how do these side effects make it into the importing file?
By mutating the global environment.
Modules are loaded into the same realm, with the same global scope and the same language-defined globals. The polyfill will create new global variables and extend the prototype objects of existing constructors.
Upvotes: 2