alex8088 / electron-vite

Next generation Electron build tooling based on Vite 新一代 Electron 开发构建工具,支持源代码保护
https://electron-vite.org
MIT License
3.51k stars 152 forks source link

打包后不能运行 #33

Closed king514jy closed 2 years ago

king514jy commented 2 years ago

Describe the bug

删除lock 重新安装,都不行。 image { "name": "resource-plaza", "version": "1.0.0", "description": "An Electron application with Vue", "main": "./out/main/index.js", "author": "", "homepage": "http://www.ledfin.cn", "scripts": { "format": "prettier --write .", "lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix", "start": "electron-vite preview", "dev": "electron-vite dev", "build": "electron-vite build", "postinstall": "electron-builder install-app-deps", "build:win": "npm run build && electron-builder --win --config", "build:mac": "npm run build && electron-builder --mac --config", "build:linux": "npm run build && electron-builder --linux --config" }, "dependencies": { "@electron-toolkit/preload": "^1.0.2", "@electron-toolkit/utils": "^1.0.2", "axios": "^0.27.2", "crypto-js": "^4.1.1", "electron-log": "^4.4.8", "electron-store": "^8.1.0", "electron-updater": "^4.6.5", "element-plus": "^2.2.17", "form-data": "^4.0.0", "fs-extra": "^10.1.0", "gsap": "^3.11.2", "vue": "^3.2.37" }, "devDependencies": { "@rushstack/eslint-patch": "^1.1.4", "@vitejs/plugin-vue": "^3.0.3", "@vue/eslint-config-prettier": "^7.0.0", "electron": "20.2.0", "electron-builder": "23.3.3", "electron-notarize": "^1.2.1", "electron-vite": "^1.0.9", "eslint": "^8.24.0", "eslint-plugin-vue": "^9.4.0", "less": "^4.1.3", "prettier": "^2.7.1", "unplugin-auto-import": "^0.11.2", "unplugin-vue-components": "^0.22.7", "vite": "^3.0.9" } }

Electron-Vite Version

1.0.10

Electron Version

20.2.0

Vite Version

3.0.9

Validations

alex8088 commented 2 years ago

@king514jy 分清那些模块是渲染进程使用的,通常渲染进程会完全打包(将依赖一并打包),所以依赖模块最好安装为devDep(有效减少安装包体积),而主进程需要的模块(deps)可以在配置文件中排除依赖,只需要打包自己的代码即可

  main: {
    build: {
      rollupOptions: {
        external: ['@electron-toolkit/utils', 'axios',...]
      }
    }
  },

下一个版本会优化增加插件来自动处理依赖

alex8088 commented 2 years ago

你的报错貌似也不是依赖问题,而是找不到入口文件,有无更具体的信息

king514jy commented 2 years ago

@alex8088 image image 该问题并不是依赖的问题,不过我按你的建议从新安装了模块。入口,我都是保持的默认结构,没有修改过。测试环境下都是正常,但是打包以后,就找不到入口文件了

king514jy commented 2 years ago

@alex8088 image

king514jy commented 2 years ago

@alex8088 image

alex8088 commented 2 years ago

@king514jy 旧脚手架上electron-builder配置有问题

alex8088 commented 2 years ago
files:
  - '!**/.vscode/*'
  - '!src/*'
  - '!electron.vite.config.{js,ts,mjs,cjs}'
  - '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}'
  - '!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}'
alex8088 commented 2 years ago

@king514jy 问题是否可以解决?

king514jy commented 2 years ago

@alex8088 可以了

alex8088 commented 2 years ago

合理配置electron-builder 的 files 属性,是优化安装包体积的重要方法