0

Currently, I have a React application built with Webpack 1.15.0.

I want to load into my application one or more precompiled bundles at runtime, like in a plugin system. The main application doesn't know the names of these bundles, but it knows that they will be in a specific directory.

I found this solution: Solution: load independently compiled Webpack 2 bundles dynamically but it seems a bit complex.

Can I accomplish this in a simpler way by using Webpack, Fusebox, Parcel or any other tool?

  • FuseBox can load any javascript or json files dynamically using the import statement. As long as this file contains module.exports it's gonna be imported as a regular module. – user3677173 Jun 05 '18 at 12:31
  • Have you heard about lazy-loaded modules? – PlayMa256 Jun 05 '18 at 13:54
  • 1
    @MatheusSilva As far as I know, lazy-loaded modules should be known at compile time. I need to provide module at runtime. The main app doesn't know them at compile time – Andrea Chiarelli Jun 05 '18 at 14:03
  • @user3677173 Does FuseBox load external compiled modules or does it compile external modules on the fly? Please, can you provide an example or a link to some documentation? – Andrea Chiarelli Jun 05 '18 at 14:06
  • https://fuse-box.org/page/dynamic-import It provides exports to the module. Therefore you would need to have these module transpiled down to es5. However, you could hook up an additional pre-processor on that – user3677173 Jun 05 '18 at 15:15
  • Thanks @user3677173. This seems going towards an acceptable solution. However, since I have bundled ES5 JavaScript, how can I export it as a commonjs module? In other words, there is a way to dynamically import compiled bundles that are not commonjs modules? – Andrea Chiarelli Jun 07 '18 at 07:29

1 Answers1

0

Thanks to the help of nchanged I reached a solution to my issue based on Fusebox.

I created a simple POC on GitHub to show how to configure two projects to allow dynamic loading of a pre-compiled bundle.

I hope this can be useful for someone else.