Background
When creating and packaging decoupled components for Layout Builder, we won't want the bundled code to include external dependencies that Drupal will load.
For example, if components are written in React, they rely on React.
If the packaging process for each component includes its version of React, this:
- It won't work. React needs one instance on the page and will error if there are multiple versions
- the size of each component will be huge!
Proposed resolution
Wordpress has a @wordpress/dependency-extraction-webpack-plugin, a webpack plugin that extracts dependencies provided by Wordpress.
We don't have enough budget to go down the complete 'roll our own' approach, which may also be overkill for now. Instead, derive configuration for Webpack externals that ensures components don't bundle dependencies Drupal will guarantee to be present.
This config will likely be part of the package at 1)
Out of scope but for future consideration:
- Create our plugin like WordPress with some Drupal-specific replacements
Comments
Comment #2
griffynh commentedComment #3
griffynh commentedComment #4
larowlanWe've solved this with native browser importmaps
I will add a core issue to support this but in the meantime we're doing this from contrib