我正在使用electron-react-boilerplate创建一个电子反应应用程序。默认情况下,开发工具会显示在屏幕上。如何才能使开发工具只在我请求时才出现,而不是在启动时出现?
此外,控制台中没有显示错误,因此开发工具不会出现,因为存在错误。

发布于 2019-03-12 13:46:45
只需在main.js文件中注释或删除此行代码(将devTools设置为false) this.mainWindow.openDevTools(); (或)将以下代码添加到
mainWindow = new BrowserWindow({
width: 1024,
height: 768,
webPreferences: {
devTools: false
}
});(或)将package.json版本更改为npm run build && build --win --x64 (或)再次安装npm
发布于 2016-12-05 00:57:51
只需添加这两行粗体代码即可。打包后,您将看不到devTool。
const electron = require('electron')
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindowvar debug =假
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600})
// and load the index.html of the app.
mainWindow.loadURL(`file://${__dirname}/index.html`)//打开DevTools。
如果(调试) mainWindow.webContents.openDevTools(),则为
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.发布于 2021-10-12 10:33:43
只需删除该行即可
mainWindow.webContents.openDevTools(false);https://stackoverflow.com/questions/40304833
复制相似问题