From 2512ad1652b27ddd2d35e904b207fe8041ffe726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Thu, 3 Nov 2022 10:01:55 +0800 Subject: [PATCH] feat: Allow use `import.meta.env.VITE_SOME_KEY` in Electron-Main --- vite.config.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index 5de5885..209a09b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,7 +2,7 @@ import { rmSync } from 'fs' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import electron from 'vite-electron-plugin' -import { customStart } from 'vite-electron-plugin/plugin' +import { customStart, loadViteEnv } from 'vite-electron-plugin/plugin' import renderer from 'vite-plugin-electron-renderer' import pkg from './package.json' @@ -17,10 +17,16 @@ export default defineConfig({ transformOptions: { sourcemap: !!process.env.VSCODE_DEBUG, }, - // Will start Electron via VSCode Debug - plugins: process.env.VSCODE_DEBUG - ? [customStart(debounce(() => console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App')))] - : undefined, + plugins: [ + ...(process.env.VSCODE_DEBUG + ? [ + // Will start Electron via VSCode Debug + customStart(debounce(() => console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App'))), + ] + : []), + // Allow use `import.meta.env.VITE_SOME_KEY` in Electron-Main + loadViteEnv(), + ], }), // Use Node.js API in the Renderer-process renderer({