caoxiemeihao / nuxt-electron

Integrate Nuxt and Electron
MIT License
169 stars 18 forks source link

Running Nuxt Dev and Electron together #35

Closed barry-huumun closed 1 year ago

barry-huumun commented 1 year ago

Hello, Thank you for this module.

I was wondering when I use the setup from the nuxt page of the module and start my app it automatically starts electron to host it.

I would like to to know how I can have differnt start scripts, One to show the normal nuxt/vite website displayed in a browser and then a different option to run electron.

Is this possible?

Thanks

caoxiemeihao commented 1 year ago

// package.json

{
  "scripts": {
    "dev": "nuxi dev",
+   "dev:web": "cross-env DEV_ENV=web && nuxi dev",
  }

// nuxt.config.ts

export default defineNuxtConfig(
+ process.env.DEV_ENV === 'web' ? {}
  : {
    modules: ['nuxt-electron'],
    electron: {
      build: [
        {
          // Main-Process entry file of the Electron App.
          entry: 'electron/main.ts',
        },
        {
          entry: 'electron/preload.ts',
          onstart(options) {
            // Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete, 
            // instead of restarting the entire Electron App.
            options.reload()
          },
        },
      ],
      renderer: {},
    },
  }
)