Linh
Linh

Reputation: 1022

How do I split main.js of my Electron application?

Electron uses main.js as the starting point of application. However, if that file contains all code which handles events of the main process, it is too long and too hard to maintain. Can I split main.js file? and how do I do?

Upvotes: 2

Views: 3999

Answers (2)

Linh
Linh

Reputation: 1022

Finally, I reached my expectation. Firstly, I imported my module at main.js by using require() method. Secondly, I used ipcMain and ipcRender to create communication channel between main process and render process.

My modules is independent of main.js so I still need to import Electron module normally.

Upvotes: 0

Vadim Macagon
Vadim Macagon

Reputation: 14837

You can split up your code into CommonJS modules which are described at depth in the Node docs.

Upvotes: 3

Related Questions