Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

分享一个多个preload的vite配置 #259

Open
mundane799699 opened this issue Nov 11, 2024 · 0 comments
Open

分享一个多个preload的vite配置 #259

mundane799699 opened this issue Nov 11, 2024 · 0 comments

Comments

@mundane799699
Copy link

找了半天也没找到现成的例子,对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: {},
    }),
  ],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant