How could (and should) we share modules between builds on a page? #434
Replies: 3 comments
-
To make sure I understand the problem correctly, are you saying that there were two different JavaScript files, let's call them
This is interesting. Am I right in thinking it sounds kind of like a |
Beta Was this translation helpful? Give feedback.
-
More precisely, the |
Beta Was this translation helpful? Give feedback.
-
What stopped the |
Beta Was this translation helpful? Give feedback.
-
We had a problem with the CMP on DCR, because the current commercial bundle that put adverts on their pages is built in frontend (that's changing, it's a hack). This means that packages present in that bundle know nothing about packages in other bundles running on DCR. The CMP was therefore being initialised twice, and consent change callbacks were being invoked by two different instances.
To get round this, we add the CMP exports to an object on
window
if they don't already exist, and use them instead if they do.A similar technique is used in DCR and maybe frontend. Finding a way to share modules with dynamically loaded es modules also feels like it would be a big win.
Would it be useful to formalise this in a structured way, so that any project had a way to:
is this helpful? if it is, does that mean we're actually doing something else wrong – i.e. is this an anti-pattern?
Webpack's federated modules seem like they could be useful, but not all projects use webpack...
Beta Was this translation helpful? Give feedback.
All reactions