6

Is it possible to require dynamic bundles at runtime with webpack? Let assume I have two separate bundles from two separate builds and I want to load modules from one bundle into another at runtime, dynamically without knowing during compilation which bundle and at what path this bundle would exist. It could be another file in directory or file from cdn.

To be detailed, prebuilt library exports something like this:

export default { Component, someFunction, otherFunction }

Every library has the same format and server provides information about path to this library at runtime. I'm thinking about something like

pathToBundle = "http://cdn" or "/bundles/name.js"
import(pathToBundle).then(module => {}).catch(error => {})

Whole gimmick is loading prebuilt bundles that are dynamically defined. I know I can do similar thing but I have to know bundles at runtime or even build them during the same bundling process and split as separate chunks.

My inspiration is Atom plugin system but for web without file system and Node context as Atom has. I have full access to server so anything server can do over http/ws could work.

I was initially thinking about something like webpack-dev-server but I don't want to rebuild whole application. My goal is to eliminate Node runtime dependency at server because I'm using other backend language for that right now and only provide already built bundles.

  • I had the same problem and described my solution in https://stackoverflow.com/questions/43163909/solution-load-independently-compiled-webpack-2-bundles-dynamically – Jörg Richter Apr 02 '17 at 13:47
  • I've created system with `window['plugin-name']` output. It's loaded from `` tag. By general bundle is looking in window scope for specified plugins and then uses them. All plugins has the same structure so it's relatively easy. My system is not for production usage because it's used as UI for Erlang monitoring tool, which is run locally. I know there are better solutions but mine for me works fine. – Tomasz Cichociński Apr 02 '17 at 14:07

0 Answers0