Concatenating multiple UMD files only exports the last component in window.GOVUKFrontend
#5047
Labels
🐛 bug
Something isn't working the way it should (including incorrect wording in documentation)
javascript
small story
Description of the issue
When concatenating multiple UMD files (
<COMPONENT_NAME>.bundle.js
), for example using Rails Assets Pipeline, only the last component will get exported inwindow.GOVUKFrontend
Steps to reproduce the issue
In a brand new folder, install the latest version of GOV.UK Frontend
As a replication of concatenating files, create the following HTML file that adds two components to a page and logs the content of
window.GOVUKFrontend
:index.html
file in your browser and open the devtools consoleActual vs expected behaviour
The logs will show only one property in
window.GOVUKFrontend
:Button
. It should list bothAccordion
andButton
as both are listed on the page.This is likely due to the UMD wrapper inside the
.bundle.js
files that resetswindow.GOVUKFrontend
in each file. Notice theglobal.GOVUKFrontend = {}
at the end of the 4th line which will resetwindow.GOVUKFrontend
as an empty object:Environment (where applicable)
The text was updated successfully, but these errors were encountered: