Using require in Electron renderer process code


#1

When developing with Electron platform there are two main javascript processes; main process and renderer process.

I want to make use of Node modules in both of these.

In main process I have made use of Node styşe require() both to require Electron’s own main process modules like app, BrowserWindow, ipc. I have also needed some node modules I have installed with npm. I have required them in the same style.

More important part is requiring node modules in a renderer process script. I have required ipc module, which is also one of Electron’s renderer process modules, with no problem as described in the sample codes in the docs. What about requiring another npm installed modules with Node style require() in to run in this renderer process by making use of browserify instead of loading them via a script tag in an index.html like file?

Since this will need a browserify compile this js file, does it conflict with the require() that Electron gives to require its built in renderer process modules, say ipc?


#2

No need for browserify. Why not skip that process, since require() is there for you in electron?


#3

Were I clear? I want to use Node style require for a non Electron module, for a npm installed one, like lodash or jQuery in Electron renderer process code.


#4

Right, if the node module gets installed to node_modules, require() will work in the render process. Try it.


#5

thanks. it works.


#6

Hi,which protocol did you use to loadURL?
file or http ?