Deluze / electron-vue-template

Simple Vue3 + Electron starter template in TypeScript, including ViteJS and Electron Builder
MIT License
534 stars 104 forks source link

Multiple Windows Support #60

Closed youngsdeveloper closed 1 month ago

youngsdeveloper commented 2 months ago

Hello.

I am trying to build an application using this template.

I need to show multiple windows in the applicacion.

I create a new .html, .vue and a .ts file for each window.

When NODE ENV is in production mode, i can choose the .html file, which choose .ts file.

But how i sould work with hot reloading mode?

Can i create multiple windows?

Thanks!

if (process.env.NODE_ENV === 'development') {
    const rendererPort = process.argv[2];
    optionsWindow.loadURL('http://localhost:${rendererPort}');
 }
  else {
    optionsWindow.loadFile(join(app.getAppPath(), 'renderer', 'index.html'));
  }
Deluze commented 2 months ago

But how i sould work with hot reloading mode?

HRM will work out of the box as long as you're connected to the Vite webserver. If you have 3 different windows (pages ?), simply set up Vue Router, and refer the window to different urls, e.g.:

localhost:${rendererPort}/about localhost:${rendererPort}/ localhost:${rendererPort}/login

etc.

youngsdeveloper commented 2 months ago

Thanks, its works now in hot reloading mode with this config.

import { createApp } from 'vue'
import './style.css';
import App from './App.vue'

import { createRouter, createWebHistory } from 'vue-router'; // Import createRouter and createWebHistory from vue-router

const routes = [
    {
      path: '/',
      component: () => import('./components/Controlador.vue') // Example route, replace with your actual component path
    },
    {
        path: '/horarios',
        component: () => import('./components/Horarios.vue') // Example route, replace with your actual component path
      },
    // Add more routes here as needed
  ];

const app = createApp(App);

const router = createRouter({
    history: createWebHistory(),
    routes
  });

app.use(router);

app.mount('#app');

For each window i add this code too

if (process.env.NODE_ENV === 'development') {
        const rendererPort = process.argv[2];
        optionsWindow.loadURL(`http://localhost:${rendererPort}/horarios`);
    }

But... What about Build Mode?

I need to send a .html file to each Window

image

This is my file structure

image

The problem is that windows html files is not in build folder and cant be accesed for Electron

How can i add this files to build process?

image

Deluze commented 2 months ago

By default, Vue is built from a single entrypoint (usually index.html) by Vite. In your situation, assuming you have the default Vite config, only 1 final html file will be generated.

As I see it there are a couple of ways how to solve this:

youngsdeveloper commented 2 months ago

Thanks a lot!

Finally i keeped multiple entry points.

Here is an example if anyone need it too:

viteconfig.js

build: {
        outDir: Path.join(__dirname, 'build', 'renderer'),
        emptyOutDir: true,
        rollupOptions: {
            input: {
              opciones: './src/renderer/opciones/opciones.html',
              horarios: './src/renderer/horarios/horarios.html', 

            }
          }

    },

Loading HTML File with VUE Component

      optionsWindow.loadFile(join(app.getAppPath(), 'renderer', 'horarios','horarios.html'));
sametcn99 commented 1 month ago

Thanks a lot!

Finally i keeped multiple entry points.

Here is an example if anyone need it too:

viteconfig.js

build: {
        outDir: Path.join(__dirname, 'build', 'renderer'),
        emptyOutDir: true,
        rollupOptions: {
            input: {
              opciones: './src/renderer/opciones/opciones.html',
              horarios: './src/renderer/horarios/horarios.html', 

            }
          }

    },

Loading HTML File with VUE Component

      optionsWindow.loadFile(join(app.getAppPath(), 'renderer', 'horarios','horarios.html'));

hey, i have multiple config files like this: image

i can't find where i write

rollupOptions: {
            input: {
              opciones: './src/renderer/opciones/opciones.html',
              horarios: './src/renderer/horarios/horarios.html', 

            }
          }

i do everything same with you. it's working on dev mode but in production it shows a blank page. do you have any example repo?

Deluze commented 1 month ago

Double check that the configs are actually used. It's likely that your project never makes it into build/renderer/horarios/.... The way how you reference the file looks correct to me.

You can verify that the structure of the built app is correct by using the asar tool to unpack the generated asar file.