0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

electron-viteで複数ページ(マルチウィンドウ)の設定

Last updated at Posted at 2025-02-13

概要

electron-viteで複数ページ(マルチウィンドウ)を設定する際に参考にしたサイトでは開発環境(Dev Server)では問題なく動いていたが、ビルドして動かすとブランクページになってしまう不具合が出ました。それを解決した備忘録です。

環境

  • Node v22.13.0
  • npm 11.0.0
  • electron 31.0.2
  • electron-vite 2.3.0
  • vite 5.3.1
  • electron-builder 24.13.3

起きていたこと

  • Dev Serverでは問題なし
  • mainプロセス内の下記の記述に問題なし
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
    subWindow.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/another.html`)
} else {
    subWindow.loadFile(join(__dirname, '../renderer/another.html'))
}

解決方法

electron.vite.config.ts にビルド設定を追加する必要がありました

 export default defineConfig({
   main: {
     plugins: [externalizeDepsPlugin()]
   },
   preload: {
     plugins: [externalizeDepsPlugin()]
   },
   renderer: {
     resolve: {
       alias: {
         '@renderer': resolve('src/renderer/src')
       }
     },
+    build: {
+       rollupOptions: {
+         input: {
+           index: join(__dirname, 'src/renderer/index.html'),
+           another: join(__dirname, 'src/renderer/another.html')
+         }
+       }
+    },
     plugins: [react()]
   }
 })

参考

こちらのコメントに助けられました。ありがとうございました。
https://github.com/electron-vite/electron-vite-react/issues/37#issuecomment-1157820888

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?