我有包含main.js的电子应用
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);
和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);
main.js几乎都是相同的,它们应该显示不同的页面。我想使用main.js启动应用程序默认值,并提供一个使用main2.js启动应用程序的选项。在我的package.json中已经介绍了
{
"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"
}
}
答案 0 :(得分:0)
您的main2
脚本应为electron ./main2
,以执行您想要的操作。
npm run start main2
将不会启动main2
,因为它运行start
(electron .
)脚本,该脚本会加载默认的电子查找模块。默认模块是您在main
字段中定义的模块