Parcel: Dynamic loads

Created on 15 Jan 2020  ·  2Comments  ·  Source: parcel-bundler/parcel

❔ Question

I am developing CMS and main feature is other developers are able to develop extensions. Each extension is a separate bundle file. Use may install those extensions through a special extensions store. After installing it menu element will appear to navigate to it.

So basically I need import based on a variable. Use open URL /users/list where users is the name of extension. So I know bundle is located at /extensions/user/bundle.js so in a router I have to load that bundle and then execute extension router. Something like

let ext = require('./extensions/' + name + '/bundle.js');
ext.route();

is that possible?

Waiting Question

All 2 comments

Yes, it's called dynamic imports https://v8.dev/features/dynamic-import

If you need this to happen at bundle time: Does this fit your description? https://github.com/parcel-bundler/parcel/issues/125

If you just want to import an arbitary url at runtime, then let ext = await import(...) would work

Was this page helpful?
0 / 5 - 0 ratings

Related issues

termhn picture termhn  ·  3Comments

mnn picture mnn  ·  3Comments

466023746 picture 466023746  ·  3Comments

algebraic-brain picture algebraic-brain  ·  3Comments

philipodev picture philipodev  ·  3Comments