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

[Help] 怎么实现多个preload文件呢 #501

Closed
LazySleep opened this issue Jul 15, 2024 · 5 comments
Closed

[Help] 怎么实现多个preload文件呢 #501

LazySleep opened this issue Jul 15, 2024 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@LazySleep
Copy link

我希望不同的窗口能够加载不同的preload,所以需要多个preload,目前有办法实现吗

@LazySleep LazySleep added the help wanted Extra attention is needed label Jul 15, 2024
@messchow
Copy link

我也卡在这个问题里

@oceanlvr
Copy link
Member

const { app, BrowserWindow } = require('electron');
const path = require('path');

function createWindow1() {
  const win1 = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload1.js')
    }
  });

  win1.loadFile('index1.html');
}

function createWindow2() {
  const win2 = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload2.js')
    }
  });

  win2.loadFile('index2.html');
}

app.whenReady().then(() => {
  createWindow1();
  createWindow2();

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow1();
      createWindow2();
    }
  });
});

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

类似这样可以解决您的问题吗?

@oceanlvr
Copy link
Member

注意需要你创建两个 index.html 入口文件

@modstart
Copy link

modstart commented Nov 9, 2024

请问一下这个问题解决了吗,vite.config.ts 是怎么配置的可以参考一下吗

@mundane799699
Copy link

请问一下这个问题解决了吗,vite.config.ts 是怎么配置的可以参考一下吗

electron-vite/vite-plugin-electron#259

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants