Skip to content

dannyatthaya/forge-externals-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@timfish/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"
                }
              ]
            }
          }
        ],
        [
          "@timfish/forge-externals-plugin",
          {
            "externals": ["native-hello-world"],
            "includeDeps": true
          }
        ]
      ]
    }
  },

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 55.4%
  • TypeScript 40.0%
  • HTML 2.6%
  • CSS 2.0%