@bn3t/forge-externals-plugin

1.0.0 • Public • Published

@bn3t/forge-externals-plugin

When using Electron with Webpack, the easiest way to support native modules is to add them to Webpack externals configuration. This tells webpack to load them from node_modules via require():

module.exports = {
  module: {
    rules,
  },
  plugins: plugins,
  resolve: {
    extensions: [".js", ".ts", ".jsx", ".tsx", ".css"],
  },
  externals: {
    // Always load `native-hello-world` via require
    "native-hello-world": "commonjs2 native-hello-world",
  },
};

This works in development but with Electron Forge + Webpack, node_modules gets excluded during packaging so the modules are missing in the packaged app.

This plugin should be added after @electron-forge/plugin-webpack and it ensures that your external modules and their dependencies are included in the packaged app.

 "config": {
    "forge": {
      "packagerConfig": {},
      "makers": [],
      "plugins": [
        [
          "@electron-forge/plugin-webpack",
          {
            "mainConfig": "./webpack.main.config.js",
            "renderer": {
              "config": "./webpack.renderer.config.js",
              "entryPoints": [
                {
                  "html": "./src/index.html",
                  "js": "./src/renderer.ts",
                  "name": "main_window"
                }
              ]
            }
          }
        ],
        [
          "@bn3t/forge-externals-plugin",
          {
            "externals": ["native-hello-world"],
            "includeDeps": true
          }
        ]
      ]
    }
  },

Readme

Keywords

none

Package Sidebar

Install

npm i @bn3t/forge-externals-plugin

Weekly Downloads

7

Version

1.0.0

License

MIT

Unpacked Size

5.5 kB

Total Files

4

Last publish

Collaborators

  • bn3t