For code like this:
const top = document.createElement("div");
top.innerText = "This is the top";
top.style = red;
export { top };
Webpack creates the following:
...
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, "top", function() { return top; });
...
const top = document.createElement("div");
top.innerText = "This is the top";
top.style = red;
How can this be working since inside the getter function() { return top; }
, top
is not yet defined when the script is executed?
Is there a particular reason why Webpack creates the export at the top and not at the bottom?
Thanks.