electron-vite-react icon indicating copy to clipboard operation
electron-vite-react copied to clipboard

How to use `utilityProcess` in this template?

Open NavaceSystem opened this issue 2 years ago • 3 comments

I'm trying to use the utility process for some background jobs but having trouble getting it to work using the example.

How do I tell vite config to include another file that will be used to spawn the utility process?

NavaceSystem avatar Oct 21 '23 07:10 NavaceSystem

I'm sorry for replying so late. Can you provide an example of using it as a minimum? I haven't tried using it before, so I don't know how to meet your needs. Thank you.

RSS1102 avatar Oct 24 '23 17:10 RSS1102

vite.config.ts

// Use Vite multi-entry
export default {
  plugins: [
    electron({
      entry: {
        // Main-Process entry file of the Electron App.
        main: 'electron/main.ts'
        test: 'electron/test.js',
      },
    }),
  ],
}

electron/main.ts

// Main process
const { port1, port2 } = new MessageChannelMain()
const child = utilityProcess.fork(path.join(__dirname, 'test.js'))
child.stdout.on('data', (data) => {
  console.log(`Received chunk ${data}`)
})

caoxiemeihao avatar Oct 31 '23 02:10 caoxiemeihao

vite.config.ts

// Use Vite multi-entry
export default {
  plugins: [
    electron({
      entry: {
        // Main-Process entry file of the Electron App.
        main: 'electron/main.ts'
        test: 'electron/test.js',
      },
    }),
  ],
}

electron/main.ts

// Main process
const { port1, port2 } = new MessageChannelMain()
const child = utilityProcess.fork(path.join(__dirname, 'test.js'))
child.stdout.on('data', (data) => {
  console.log(`Received chunk ${data}`)
})

Thanks, I'll try this out.

NavaceSystem avatar Nov 17 '23 08:11 NavaceSystem