vite-plugin-electron编译时不会在主文件夹内创建嵌套文件夹

kgqe7b3p  于 2023-06-27  发布在  Electron
关注(0)|答案(1)|浏览(192)

我试着像这样构造我的电子文件夹:

但是vite-plugin-electron不会创建API文件夹,而是在根文件夹编译:

这是我的vite配置文件:

import { defineConfig } from "vite";
import electron from "vite-plugin-electron";
import renderer from "vite-plugin-electron-renderer";
import react from "@vitejs/plugin-react";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    electron([
      {
        // Main-Process entry file of the Electron App.
        entry: "electron/main.ts",
      },
      {
        entry: "electron/preload.ts",
        onstart(options) {
          // Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
          // instead of restarting the entire Electron App.
          options.reload();
        },
      },
      {
        entry: "electron/api/upload.ts",
      },
    ]),
    renderer(),
  ],
});

我查看了vite-plugin-electron docs,但没有找到可以自己指定的outDir属性。

r6vfmomb

r6vfmomb1#

我在他们的github repo中打开了一个问题,他们帮助了我。这就是解决方案:

import { defineConfig } from "vite";
import electron from "vite-plugin-electron";
import renderer from "vite-plugin-electron-renderer";
import react from "@vitejs/plugin-react";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    electron([
      {
        // Main-Process entry file of the Electron App.
        entry: "electron/main.ts",
      },
      {
        entry: "electron/preload.ts",
        onstart(options) {
          // Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
          // instead of restarting the entire Electron App.
          options.reload();
        },
      },
      {
        entry: "electron/IpcRenderer/upload.ts",
        vite: {
          build: {
            outDir: "dist-electron/IpcRenderer",
          },
        },
      },
      {
        entry: "electron/IpcMain/upload.ts",
        vite: {
          build: {
            outDir: "dist-electron/IpcMain",
          },
        },
      },
    ]),
    renderer(),
  ],
});

这将把文件编译到outDir属性上的指定目录中

相关问题