GoogleChromeLabs / carlo

Web rendering surface for Node applications
Apache License 2.0
9.31k stars 309 forks source link

Use CommonJS require to import NPM modules like in Electron? #102

Open trusktr opened 5 years ago

trusktr commented 5 years ago

Is it possible to use require like in Electron to import NPM modules in the browsing context?

If such feature doesn't exist, is it possible to write code for the feature in JS? Or would it require C++ in the lower levels?

Are carloFunctions defined with Window.exposeFunction able to return references? Or only serializable data? I can see how to implement require if it returns references.

pavelfeldman commented 5 years ago

There is no require in the browser context and there is no good way to emulate require in the user land JS. I also would like to keep the web side as close to the real web as possible.

carloFunction is only useful for small and demo apps. It only returns serialized types.

RPC is what should be used for real world applications. Check out how app.load gets and returns rpc handles that can be used across the world. That's how front-end gets instances of the backend objects and vice versa. Check out the bundled examples (and tests), they are all using the rpc.

Simran-B commented 5 years ago

Can https://requirejs.org/ be used for that somehow?