Paciolan / remote-module-loader

Loads a CommonJS module from a remote URL for the Browser or Node.js.
MIT License
85 stars 21 forks source link

Named Exports #32

Closed seikosantana closed 1 year ago

seikosantana commented 1 year ago

Hi, is there a way to perform named imports using this library? I managed to fetch and I can see the result of loadRemodeModule, but I don't see any way to get what I exported beside export default.

I am exporting it like

import { IotaboardDashboard } from "./IotaboardDashboard";
import _backgroundInit from "./background";

// Important: do not change name
export const backgroundInit = _backgroundInit;

export default IotaboardDashboard;
joelnet commented 1 year ago

Yes, named exports do work. I'll have to update the documentation, but it is supported.

In this example you can see the code is calling .default() you can change that to the name of your export.

/**
 * src/index.js
 */

import loadRemoteModule from "./lib/loadRemoteModule";

const main = async () => {
  const myModule = await loadRemoteModule(
    "http://fake.url/modules/my-module.js"
  );
  const value = myModule.default();
  console.log({ value });
};

main();
seikosantana commented 1 year ago

Ah yeah sorry forgot to close the issue. I previously tried the method just like you described above and it didn't work. After further investigating I realized that it was loading a disk-cached version.

Again, thanks a lot for the awesome library :grinning: