Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use utilityProcess in this template? #183

Open
NavaceSystem opened this issue Oct 21, 2023 · 3 comments
Open

How to use utilityProcess in this template? #183

NavaceSystem opened this issue Oct 21, 2023 · 3 comments

Comments

@NavaceSystem
Copy link

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
Copy link
Member

RSS1102 commented Oct 24, 2023

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
Copy link
Member

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants