electron-forge-plugin-dependencies
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

electron-forge-plugin-dependencies

Help Electron Forge Vite/Webpack project collect dependencies.

NPM version NPM Downloads

Install

npm i -D electron-forge-plugin-dependencies

Usage

forge.config.js

module.exports = {
  plugins: [
    {
      name: 'electron-forge-plugin-dependencies',
      config: {/* config */},
    },
  ],
};

forge.config.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;

API (Define)

export interface DependenciesPluginConfig {
  /**
   * The dependencies package by Electron Forge, default to the `dependencies` in the current project's package.json.
   */
  dependencies?: string[]
  /**
   * Function to filter copied files/directories. Return `true` to copy the item, `false` to ignore it.
   * Can also return a `Promise` that resolves to `true` or `false` (or pass in an `async` function).
   */
  filter?: (src: string, dest: string) => boolean | Promise<boolean>
}

Why

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.

/electron-forge-plugin-dependencies/

    Package Sidebar

    Install

    npm i electron-forge-plugin-dependencies

    Weekly Downloads

    30

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    20 kB

    Total Files

    15

    Last publish

    Collaborators

    • caoxie