I discovered that the simple electron-vite-react
app with two windows works fine in development mode
, but not in "packaged mode":
When commenting the relative part in vite.config.js
:
build: {
rollupOptions: {
input: {
index: join(__dirname, 'index.html'),
//index_A: join(__dirname, 'index_A.html'),
},
},
},
and in electron/main/index.ts
:
app.whenReady().then( () => {
createMainWindow()
//Menu.setApplicationMenu(menu)
})
both dev mode
and packaged mode
work fine:
raphy@pc:~/VitePlayground$ yarn run build
yarn run v1.22.15
$ tsc && vite build && electron-builder
(node:21908) [DEP0025] DeprecationWarning: sys is deprecated. Use util instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
vite v2.9.12 building for production...
โ 1 modules transformed.
dist/electron/preload/ipcpreload.js 2.50 KiB / gzip: 0.99 KiB
dist/electron/preload/ipcpreload.js.map 11.79 KiB
vite v2.9.12 building for production...
โ 1 modules transformed.
dist/electron/main/index.js 1.34 KiB / gzip: 0.77 KiB
vite v2.9.12 building for production...
โ 36 modules transformed.
dist/index.html 0.61 KiB
dist/style.9f994278.css 1.46 KiB / gzip: 0.63 KiB
dist/index.90df7efd.js 140.63 KiB / gzip: 45.34 KiB
โข electron-builder version=23.0.3 os=5.13.0-51-generic
โข loaded configuration file=/home/raphy/VitePlayground/electron-builder.json5
โข writing effective config file=release/2.0.0/builder-effective-config.yaml
โข packaging platform=linux arch=x64 electron=19.0.4 appOutDir=release/2.0.0/linux-unpacked
โข building target=AppImage arch=x64 file=release/2.0.0/YourAppName-Linux-2.0.0.AppImage
โข application Linux category is set to default "Utility" reason=linux.category is not set and cannot map from macOS docs=https://www.electron.build/configuration/linux
Done in 8.18s.

When index_A
is activated in vite.config.ts
:
build: {
rollupOptions: {
input: {
index: join(__dirname, 'index.html'),
index_A: join(__dirname, 'index_A.html'),
},
},
},
and the menu
part is activatedin /electron/main/index.ts
:
app.whenReady().then( () => {
createMainWindow()
Menu.setApplicationMenu(menu)
})
the development mode
works fine as before :
raphy@pc:~/VitePlayground$ yarn dev
yarn run v1.22.15
$ vite
(node:22320) [DEP0025] DeprecationWarning: sys is deprecated. Use util instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
vite v2.9.12 dev server running at:
> Local: http://127.0.0.1:7777/
ready in 215ms.
vite v2.9.12 building for development...
watching for file changes...
build started...
vite v2.9.12 building for development...
watching for file changes...
build started...
โ 1 modules transformed.
transforming (1) electron/main/index.tsdist/electron/preload/ipcpreload.js 4.21 KiB / gzip: 1.21 KiB
dist/electron/preload/ipcpreload.js.map 12.28 KiB
built in 92ms.
โ 2 modules transformed.
dist/electron/main/index.js 3.95 KiB / gzip: 1.25 KiB
built in 92ms.
[22373:0618/165407.120600:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.
4:54:07 PM [vite] warning: Top-level "this" will be replaced with undefined since this file is an ECMAScript module
32 | lineNumber: 15,
33 | columnNumber: 13
34 | }, this)
| ^
35 | }, void 0, false, {
36 | fileName: _jsxFileName,
Plugin: vite:esbuild
File: /home/raphy/VitePlayground/src/app/components/App.tsx

But the production mode
, the release
produced with yarn run build
does not work anymore :
raphy@pc:~/VitePlayground$ yarn run build
yarn run v1.22.15
$ tsc && vite build && electron-builder
(node:22549) [DEP0025] DeprecationWarning: sys is deprecated. Use util instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
vite v2.9.12 building for production...
โ 1 modules transformed.
dist/electron/preload/ipcpreload.js 2.50 KiB / gzip: 0.99 KiB
dist/electron/preload/ipcpreload.js.map 11.79 KiB
vite v2.9.12 building for production...
โ 2 modules transformed.
dist/electron/main/index.js 2.40 KiB / gzip: 1.02 KiB
vite v2.9.12 building for production...
โ 39 modules transformed.
dist/index_A.html 0.67 KiB
dist/index.html 0.67 KiB
dist/index.2ba947a6.js 1.71 KiB / gzip: 0.75 KiB
dist/index_A.ab7b482d.js 0.33 KiB / gzip: 0.25 KiB
dist/style.9f994278.css 1.46 KiB / gzip: 0.63 KiB
dist/index.8bf949c4.js 139.11 KiB / gzip: 44.69 KiB
โข electron-builder version=23.0.3 os=5.13.0-51-generic
โข loaded configuration file=/home/raphy/VitePlayground/electron-builder.json5
โข writing effective config file=release/2.0.0/builder-effective-config.yaml
โข packaging platform=linux arch=x64 electron=19.0.4 appOutDir=release/2.0.0/linux-unpacked
โข building target=AppImage arch=x64 file=release/2.0.0/YourAppName-Linux-2.0.0.AppImage
โข application Linux category is set to default "Utility" reason=linux.category is not set and cannot map from macOS docs=https://www.electron.build/configuration/linux
Done in 8.11s.
raphy@pc:~/VitePlayground$
raphy@pc:~/VitePlayground/release/2.0.0$ ./YourAppName-Linux-2.0.0.AppImage
[22710:0618/165813.204491:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.

I tried to modify the path also in packaged mode
:
if (app.isPackaged) {
//WindowTypeA.loadFile(join(__dirname, '../../index_A.html'))
WindowTypeA.loadURL(url + '/../../index_A.html')
} else {
WindowTypeA.loadURL(url + '/../../index_A.html')
WindowTypeA.webContents.openDevTools()
}
But again it does not work

Based on what I read here: https://vitejs.dev/guide/build.html#multi-page-app the build configuration
:
build: {
rollupOptions: {
input: {
index: join(__dirname, 'index.html'),
index_A: join(__dirname, 'index_A.html'),
},
},
seem ok
Shouldn't be doing everyhing electron-builder
?
The boilerplate
indicated in the electron-builder
DOCS : https://www.electron.build/#boilerplates electron-vite-vue
, in the build
phase : https://github.com/electron-vite/electron-vite-vue/blob/main/package.json#L10 uses the same steps: vite build && electron-builder
What am I missing or / and doing wrongly in thepackaging phase
?
Here you can find the repo, which is nothing else than the electron-vite-react
app, where I added a second window, that can be opened from the menu
:
https://github.com/raphael10-collab/VitePlayground.git
Looking forward to your kind help