When concatenating multiple UMD files (<COMPONENT_NAME>.bundle.js), for example using Rails Assets Pipeline, only the last component will get exported in window.GOVUKFrontend
Steps to reproduce the issue
In a brand new folder, install the latest version of GOV.UK Frontend
npm install govuk-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:
Open the index.html file in your browser and open the devtools console
Actual vs expected behaviour
The logs will show only one property in window.GOVUKFrontend: Button. It should list both Accordion and Button as both are listed on the page.
This is likely due to the UMD wrapper inside the .bundle.js files that resets window.GOVUKFrontend in each file. Notice the global.GOVUKFrontend = {} at the end of the 4th line which will reset window.GOVUKFrontend as an empty object:
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
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)