我曾经用电子来创建桌面应用程序,但是我有一个问题让我先展示我的代码
我的server.js
'use strict';
var loopback = require('loopback');
var boot = require('loopback-boot');
var path = require('path');
var bodyParser = require('body-parser');
var app = module.exports = loopback();
// configure view handler
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(loopback.token());
console.log("hi")
app.start = function() {
// start the web server
console.log("hi1")
return app.listen(function() {
app.emit('started');
var baseUrl = app.get('url').replace(/\/$/, '');
console.log('Web server listening at: %s', baseUrl);
if (app.get('loopback-component-explorer')) {
var explorerPath = app.get('loopback-component-explorer').mountPath;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
}
});
};
boot(app, __dirname, function(err) {
if (err) throw err;
// start the server if `$ node server.js`
if (require.main === module)
console.log("hi2")
app.start();
});
这是我的电子index.js
'use strict';
const electron = require('electron');
const {app, BrowserWindow,crashReporter} = electron;
require(__dirname+'/server/server.js');
let mainWindow;
function onClosed() {
mainWindow = null;
}
function createMainWindow() {
const win = new BrowserWindow({
width: 600,
height: 400
});
win.loadURL('http://localhost:3000/');
win.maximize();
win.on('closed', onClosed);
return win;
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate-with-no-open-windows', () => {
if (!mainWindow) {
mainWindow = createMainWindow();
}
});
app.on('ready', () => {
mainWindow = createMainWindow();
});
,在我的程序包json中(我的应用程序开始时,我的意思是在电子之前,运行服务器需要程序包json) 我修改它以运行电子应用程序
{
"name": "login",
"version": "0.1.0",
"productName": "login",
"main":"index.js",
"engines": {
"node": ">=4"
},
"electronVersion": "^3.0.2",
"scripts": {
"start": "electron .",
"build": "electron-packager . $npm_package_productName --out=dist --ignore='^/dist$' --prune --asar --all --version=$npm_package_electronVersion",
"posttest": "npm run lint && nsp check"
},
"keywords": [
"electron-app"
],
"dependencies": {
// required dependencies to run project
"electron-debug": "^2.0.0",
},
"devDependencies": {
"electron": "^3.0.2",
"electron-winstaller": "^2.7.0",
},
}
现在我的问题是,如果我执行上述server.js示例中的console.log(“ hii”)console.log(“ hi1”)和console.log(“ hi2”)并删除了它,则它可以正常工作全部3 console.log然后电子应用程序不启动应用程序谁能告诉我这是什么问题