分享一个多个preload的vite配置
Opened this issue · 0 comments
mundane799699 commented
找了半天也没找到现成的例子,对vite也不熟。
自己摸索了半天终于试出来了,分享给大家让你们少踩点坑。
multi preload config sample:
vite.config.ts
import { defineConfig, loadEnv } from "vite";
import path from "node:path";
import electron from "vite-plugin-electron/simple";
import react from "@vitejs/plugin-react";
import pkg from "./package.json";
// https://vitejs.dev/config/
export default defineConfig({
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
plugins: [
react(),
electron({
main: {
// Shortcut of `build.lib.entry`.
entry: [
"electron/main.ts",
"electron/worker.ts",
"electron/sqlite3.ts",
],
vite: {
build: {
rollupOptions: {
external: Object.keys(
"dependencies" in pkg ? pkg.dependencies : {}
),
},
},
},
},
preload: {
input: [
path.join(__dirname, "electron/preload.ts"),
path.join(__dirname, "electron/preload2.ts"),
],
vite: {
build: {
rollupOptions: {
output: {
inlineDynamicImports: false,
},
},
},
},
},
// Ployfill the Electron and Node.js API for Renderer process.
// If you want use Node.js in Renderer process, the `nodeIntegration` needs to be enabled in the Main process.
// See 👉 https://github.com/electron-vite/vite-plugin-electron-renderer
renderer: {},
}),
],
});