2

Is there a way to instruct webpack to build and provide shared dependencies, making a root container application the default sharing host, without actually consuming said dependencies in a root container app?

I'd like to treat a very light root application as a shared dependency provider for the purpose of curating versions, and to just apply some control over where shared packages are requested from by default.

The problem of course is that webpack won't build dependencies that aren't consumed by the app itself.

My desired behavior is that the container builds a list of packages, as though they were imported in source, but only requests them async at the behest of child container apps. I can fake it easily by creating empty dynamic imports:

import('dep1');
import('dep2');

...but this generates a request for the chunks immediately. The root application doesn't technically need these dependencies, and I'd like them to only be requested on demand, not eager loaded.

Is this possible? I've been seeking examples but haven't seen it demonstrated. It seems like a reasonable use case to me, but perhaps I'm missing something?

numbers1311407
  • 33,686
  • 9
  • 90
  • 92

1 Answers1

0

While not an ideal answer, I wanted to post this in case others found the question and need something that works.

I was halfway there in the original question. You can simply define a function which contains the dynamic imports without actually initiating them, e.g.

const thisIsNeverActuallyCalled = () => {
  import('dep1')
  import('dep2')
  // ... and so on
}

This is enough to get the dependencies bundled and provided up front to any child containers which may import them.

numbers1311407
  • 33,686
  • 9
  • 90
  • 92