How to use `utilityProcess` in this template?
NavaceSystem opened this issue · 3 comments
NavaceSystem commented
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?
RSS1102 commented
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.
caoxiemeihao commented
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}`)
})
NavaceSystem commented
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.