electron-vite/vite-plugin-electron

dist-electron\main\index.js not exist app.asar问题

yangdezuan opened this issue · 4 comments

你好,升级后最近发现打包的时候出现 这个问题, 之前是正常的。
⨯ Application entry file "dist-electron\main\index.js" in the "I:\wm\web\dev\electron\pwlivetest\release\1.0.1\win-unpacked\resources\app.asar" does not exist. Seems like a wrong configuration. failedTask=build stackTrace=Error: Application entry file "dist-electron\main\index.js" in the "I:\wm\web\dev\electron\pwlivetest\release\1.0.1\win-unpacked\resources\app.asar" does not exist. Seems like a wrong configuration.

同样的问题,是由于将构建文件默认生成到了dist-electron文件夹中,在package.jsonbuildfiles中只包含了dist文件夹,而dist文件夹没有electron构建的入口文件所导致。
解决办法
1、将dist-electron文件夹复制到dist中,且将package.jsonmain指向新的位置,如"main": "dist/dist-electron/main.js", 之后在打包就可以解决报错问题。
2、electron({ entry: 'electron/main.ts', vite: { build: { outDir: "dist/electron", }, }, }) 添加了build的位置,自动build到dist文件内,将package.jsonmain指向修改正确,就可以顺利打包了。

将 dist-electron 放到 electron-builder.json5 中的 files 中即可。可以参考最新的示例代码。

采用这种方法,打包可以成功,不知道为什么运行起来是白屏。。。

The same problem is caused by generating the build file into dist-electronthe folder by default. The folder in the package.json.txt file only contains the folder, but the folder does not have the built entry file. Solution 1. Copy the folder to the .txt file and point to the new location, such as .txt file. Then the error problem can be solved when packaging. 2. Add the build location, automatically build it into the dist file, modify the pointing of the file correctly, and you can package it smoothly.build``files``dist``dist``electron``dist-electron``dist``package.json``main``"main": "dist/dist-electron/main.js"``electron({ entry: 'electron/main.ts', vite: { build: { outDir: "dist/electron", }, }, })``package.json``main

This solved my problem!

My package.json got like this:

{
  ...
   "main": "dist/electron/main.js",
  ...
}

and my vite.config.ts got like this:

export default defineConfig({
  plugins: [
    electron({
      entry: 'electron/main.ts',
      vite: {
        build: {
          outDir: 'dist/electron',
        },
      },
    }),
    ...
}

This way I keep all build files inside the dist folder and Electron Builder finds everything without any problem.