Reputation: 783
For simplicity I want to keep my main.js clear and outsource classes for the different windows in separate files. I have no idea how to reference the files. It should look like this
//main.js
const electron = require('electron');
const { app } = electron;
app.on('ready', () => {
createWindow(); //
});
And the second file with my main page:
// mainPage.js
const { BrowserWindow } = require('electron').remote
function createWindow() {
let win = new BrowserWindow({ width: 800, height: 600 });
win.loadFile('mainPage.html');
/* more code related to that page */
}
But electron doesn't recognize my mainPage.js file, usually in JavaScript this is no problem.
Upvotes: 2
Views: 1112
Reputation: 120498
So at the end of mainPage.js
:
module.exports = { createWindow }
and at the top of main.js
const { createWindow } = require("./mainPage") //assuming files in same dir
See https://nodejs.org/api/modules.html#modules_modules for more information about how this works.
Upvotes: 3