首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让开发工具在Electron中默认不显示在屏幕上?

如何让开发工具在Electron中默认不显示在屏幕上?
EN

Stack Overflow用户
提问于 2016-10-28 20:11:18
回答 3查看 25.8K关注 0票数 26

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

此外,控制台中没有显示错误,因此开发工具不会出现,因为存在错误。

EN

回答 3

Stack Overflow用户

发布于 2019-03-12 13:46:45

只需在main.js文件中注释或删除此行代码(将devTools设置为false) this.mainWindow.openDevTools(); (或)将以下代码添加到

代码语言:javascript
复制
     mainWindow = new BrowserWindow({ 
     width: 1024,
     height: 768,
     webPreferences: {
      devTools: false
      }
   });

(或)将package.json版本更改为npm run build && build --win --x64 (或)再次安装npm

票数 29
EN

Stack Overflow用户

发布于 2016-12-05 00:57:51

只需添加这两行粗体代码即可。打包后,您将看不到devTool。

代码语言:javascript
复制
const electron = require('electron')
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow

var debug =假

代码语言:javascript
复制
// 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(),则为

代码语言:javascript
复制
  // 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.
票数 4
EN

Stack Overflow用户

发布于 2021-10-12 10:33:43

只需删除该行即可

代码语言:javascript
复制
mainWindow.webContents.openDevTools(false);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40304833

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档