Electron - How to add react dev tool

后端 未结 3 1773
眼角桃花
眼角桃花 2021-01-14 01:01

What is the easy way to add react dev tool to electron window? I try add the extension hash

BrowserWindow.addDevToolsExtension(\'path/to/extension/ade2343nd23

3条回答
  •  爱一瞬间的悲伤
    2021-01-14 01:12

    You can add react devtools directly from your main.js file like this

    const installExtensions = async () => {
      const installer = require('electron-devtools-installer')
      const forceDownload = !!process.env.UPGRADE_EXTENSIONS
      const extensions = [
        'REACT_DEVELOPER_TOOLS',
        'REDUX_DEVTOOLS',
        'DEVTRON'
      ]
    
      return Promise
        .all(extensions.map(name => installer.default(installer[name], forceDownload)))
        .catch(console.log)
    }
    
    app.on('ready', async () => {
      if (dev && process.argv.indexOf('--noDevServer') === -1) {
        await installExtensions()
      }
      createWindow()
    })
    

提交回复
热议问题