Paciolan / remote-component

Dynamically load a React Component from a URL
MIT License
599 stars 48 forks source link

Using import() syntax in dependency list #45

Closed monmush closed 2 years ago

monmush commented 3 years ago

Recently I have migrated out project prom CRA to ViteJS. As I understand, Vite does not support require() syntax so I have to make a little change in remote-component.config.js to use the import() instead.

`export const resolve = { react: import('react'),

antd: import('antd'), ['react-query']: await import('react-query'),

} `

However, it seems like there is something to do with the import and module system so remote-component can not resolve the dependencies

error TypeError: o.default.createContext is not a function at eval (eval at <anonymous> (loadRemoteModule.ts:41), <anonymous>:3:26391) at loadRemoteModule.ts:42

@joelnet Do you have any idea or suggestion on regarding the issue?. I really appreciated your help. Thanks!

joelnet commented 2 years ago

Have a look at the section Injecting Dependencies without Webpack. You should be able to use any bundler using this method.

As for the remote-component.config.js you can do something like this:

import react from 'react';

export const resolve = {
  react
};