Reputation: 1115
I have electron app with main.js which contains
const electron = require('electron')
const { app, BrowserWindow } = require('electron')
function createWindow(){
let win = new BrowserWindow({width: 800, height: 600})
console.log("loading file index1");
win.loadFile('index1.html')
}
app.on('ready',createWindow);
and main2.js
const electron = require('electron')
const { app, BrowserWindow } = require('electron')
function createWindow(){
let win = new BrowserWindow({width: 400, height: 400})
console.log("loading file index2");
win.loadFile('index2.html');
}
app.on('ready',createWindow);
both main.js are almost identical and they should show different pages. I want to start the app default with main.js and provide an option to start the app with main2.js . in my package.json I have introduced
{
"name": "mytestapp",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron .",
"test:e2e": "./node_modules/mocha/bin/mocha tests/test.js",
"main2": "npm run start ./main2.js",
"debug": "./node_modules/.bin/electron ./main2.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^4.0.8",
"mocha": "^3.5.3",
"spectron": "^5.0.0"
},
"dependencies": {
"start": "^5.1.0"
}
}
now when I start the app with npm run main2
i still get the page index1 and the app dose not log anything
Upvotes: 0
Views: 2695
Reputation: 5521
Your main2
script should be electron ./main2
to do what you want.
npm run start main2
won't start main2
, because it runs start
(electron .
) script, which loads the default module electron finds. The default module is what you defined in main
field
Upvotes: 2