Multiple React cras with aem-clientlib-generator
Hi folks,
I am integrating a bunch of different React CRAs into an AEM Page template. I am not using the "SPA Editor". I'm just integrating them directly with custom components, but I am using the very handy aem-clientlib-generator npm plugin to create the clientlibs from "build/static" and copy them into my AEM codebase.
I looked at the JS for each CRA and I see that the default CRA webpack configuration has "chunked" the JS. There is one file called "main.<hash>.chunk.js", one called "runtime-main.<hash>.js" and one called "2.<hash>.chunk.js".
From what I can see, "main.<hash>.chunk.js" is my colleagues' React code and "2.<hash>.chunk.js" is the React libraries, react and react-dom. Now I would like to share the "2.<hash>.chunk.js" files for all the CRAs rather than have these react libraries duplicated lots of times in lots of clientlibs in my AEM page. The problem is when I look into the JS file, there is some webpack configuration i.e. a webpack object called webpackJsonp<CRA name> at the top of the file so I can't throw away all of these files except one which was my original hope.
I know that this is more of a Webpack/react question than an AEM question but I was hoping someone might have come across this before and know what to do.
I noticed a similar but not quite the same question whereby the OP had multiple CRAs with the same name which didn't work.
thx
Fiona