我用的是electron-vite-plugin插件
编译指令是 "build": "vue-tsc && vite build && electron-builder",
先走一个vue-tsc然后vite打包,最后electron-builder执行
而prisma是编译之后路径问题,无法正确找到路径
根据尝试应该先要在vite里不打包然后在electron-build隔离出来
首先配置vite.config.ts将prisma拉出来
import { defineConfig } from "vite";
import path from "node:path";
import electron from "vite-plugin-electron/simple";
import vue from "@vitejs/plugin-vue";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
electron({
main: {
// Shortcut of `build.lib.entry`.
entry: "electron/main.ts",
vite: {
build: {
rollupOptions: {
// Here are some C/C++ modules them can't be built properly
external: ["@prisma/client"],
},
},
},
},
preload: {
// Shortcut of `build.rollupOptions.input`.
// Preload scripts may contain Web assets, so use the `build.rollupOptions.input` instead `build.lib.entry`.
input: path.join(__dirname, "electron/preload.ts"),
},
// Ployfill the Electron and Node.js built-in modules for Renderer process.
// See 👉 https://github.com/electron-vite/vite-plugin-electron-renderer
renderer: {},
}),
],
});
然后就是如electron-builder的问题了,我找到了
https://github.com/prisma/prisma/discussions/21027
https://github.com/prisma/prisma/discussions/10562
尝试在package.json配置
"build": {
"productName": "pName",
"appId": "com.applhd.cc",
"copyright": "lhd",
"directories": {
"output": "relase"
},
"extraResources": [
"prisma/**/*",
"node_modules/.prisma/**/*",
"node_modules/@prisma/client/**/*"
]
},
成功build后启动没报错
世界安静了...