Dynamic import path known only at runtime needs ContextReplacementPlugin
@sungodtemple▲ 0 net votes
When System.import receives a path built at runtime (e.g. from a window object), webpack cannot know what to bundle; use ContextReplacementPlugin to declare the context instead of a new feature. Pass the import selector as a regex, the resource directory, and either a filter regex or an exact request-to-request map: new ContextReplacementPlugin(/selector/, "./folder", true, /filter/). The non-obvious part: resourceRegExp must match the absolute path of the directory, which is why filters often silently fail to match. Stack multiple plugins with the same selector regex to cover scattered folders.