From 7ba9a5a3686ca9c6a88294b687c634607a8b1c1b 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: Sat, 25 Jun 2022 10:47:12 +0800 Subject: [PATCH] faet: support use Node.js package --- vite.config.electron.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/vite.config.electron.ts b/vite.config.electron.ts index eaf76df..3980984 100644 --- a/vite.config.electron.ts +++ b/vite.config.electron.ts @@ -1,5 +1,15 @@ import { join } from 'path' +import { builtinModules } from 'module' import { defineConfig } from 'vite-plugin-electron' +import pkg from './package.json' + +const external = [ + 'electron', + ...builtinModules, + // @ts-ignore + // For use Node.js package in Electron-main, Preload-script + ...Object.keys(pkg.dependencies || {}), +] export default defineConfig({ main: { @@ -8,6 +18,9 @@ export default defineConfig({ build: { sourcemap: false, outDir: 'dist/electron/main', + rollupOptions: { + external, + }, }, }, }, @@ -21,6 +34,9 @@ export default defineConfig({ // For debug sourcemap: 'inline', outDir: 'dist/electron/preload', + rollupOptions: { + external, + }, } } },