Help Electron Forge Vite/Webpack project collect dependencies
npm install electron-forge-plugin-dependenciesHelp Electron Forge Vite/Webpack project collect dependencies.


``bash`
npm i -D electron-forge-plugin-dependencies
forge.config.js
`js`
module.exports = {
plugins: [
{
name: 'electron-forge-plugin-dependencies',
config: {/ config /},
},
],
};
forge.config.ts
`ts
import type { ForgeConfig } from '@electron-forge/shared-types';
import { DependenciesPlugin } from 'electron-forge-plugin-dependencies';
const config: ForgeConfig = {
plugins: [
new DependenciesPlugin({/ config /}),
],
};
export default config;
`
`tsdependencies
export interface DependenciesPluginConfig {
/**
* The dependencies package by Electron Forge, default to the in the current project's package.json.true
*/
dependencies?: string[]
/**
* Function to filter copied files/directories. Return to copy the item, false to ignore it.Promise
* Can also return a that resolves to true or false (or pass in an async function).``
*/
filter?: (src: string, dest: string) => boolean | Promise
}
Oftentimes, Electron Forge cannot build some third-party modules properly, especially C/C++ native modules. This is because they cannot be properly processed by Vite/Webpack, but they can be loaded normally by Node.js with the require function.
In order to ensure that an Electron application can work properly, we need to collect them into the application's node_modules. This seems stupid, but it works.