Package to rebuild native Node.js modules against the currently installed Electron version
Перейти к файлу
Samuel Attard 935f4c9d3d Merge pull request #180 from romaincointepas/patch-1
CLI default types should be "prod,optional"
2017-06-14 17:49:57 +10:00
src Merge pull request #180 from romaincointepas/patch-1 2017-06-14 17:49:57 +10:00
test Replace fs-promise with fs-extra 2017-06-09 05:45:42 +02:00
.appveyor.yml Set up tests 2016-12-31 17:27:29 +13:00
.gitignore Ignore stuff 2015-05-04 00:01:46 -07:00
.npmignore Set up our packaging for TypeScript 2017-03-28 15:36:29 -07:00
.travis.yml Comment travis workaround 2017-06-09 06:14:46 +02:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 2016-01-22 14:28:48 -08:00
README.md Cleanup readme 2017-02-26 14:55:57 -08:00
contributing.md add contributing doc 2016-08-05 10:45:54 -07:00
package.json Replace fs-promise with fs-extra 2017-06-09 05:45:42 +02:00
tsconfig.json Fixup to Package 2017-03-28 16:10:59 -07:00
tslint.json Set up our packaging for TypeScript 2017-03-28 15:36:29 -07:00

README.md

Electron Rebuild

This executable rebuilds native Node.js modules against the version of Node.js that your Electron project is using. This allows you to use native Node.js modules in Electron apps without your system version of Node.js matching exactly (which is often not the case, and sometimes not even possible).

How does it work?

Install the package with --save-dev:

npm install --save-dev electron-rebuild

Then, whenever you install a new npm package, rerun electron-rebuild:

$(npm bin)/electron-rebuild

Or if you're on Windows:

.\node_modules\.bin\electron-rebuild.cmd

If you have a good node-gyp config but you see an error about a missing element on Windows like Could not load the Visual C++ component "VCBuild.exe", try to launch electron-rebuild in an npm script:

"scripts": {
  "rebuild": "electron-rebuild -f -w yourmodule"
}

and then

npm run rebuild

CLI Arguments

Usage: electron-rebuild --version [version] --module-dir [path]

Options:
  -h, --help                   Show help                               [boolean]
  -v, --version                The version of Electron to build against
  -f, --force                  Force rebuilding modules, even if we would skip
                               it otherwise
  -a, --arch                   Override the target architecture to something
                               other than your system's
  -m, --module-dir             The path to the app directory to rebuild
  -w, --which-module           A specific module to build, or comma separated
                               list of modules
  -e, --electron-prebuilt-dir  The path to electron-prebuilt
  -d, --dist-url               Custom header tarball URL
  -t, --types                  The types of dependencies to rebuild.  Comma
                               seperated list of "prod", "dev" and "optional".
                               Default is "prod,optional"
  -p, --parallel               Rebuild in parallel, this is enabled by default
                               on macOS and Linux
  -s, --sequential             Rebuild modules sequentially, this is enabled by
                               default on Windows

Copyright 2016

How can I use this with Electron Forge?

This package is automatically used with Electron Forge when packaging an Electron app.

How can I integrate this into Electron Packager?

electron-rebuild provides a function compatible with the afterCopy hook for Electron Packager. For example:

import packager from 'electron-packager';
import rebuild from 'electron-rebuild';

packager({
  // … other options
  afterCopy: [(buildPath, electronVersion, platform, arch, callback) => {
    rebuild(buildPath, electronVersion, arch)
      .then(() => callback())
      .catch((error) => callback(error));
  }],
  // … other options
});

How can I integrate this into Grunt / Gulp / Whatever?

electron-rebuild is also a library that you can just require into your app or build process. It has a very simple API:

import rebuild from 'electron-rebuild';

// Public: Rebuilds a node_modules directory with the given Electron version.
//
// appPath - An absolute path to your app's directory.  (The directory that contains your node_modules)
// electronVersion - The version of Electron to rebuild for
// arch (optional) - Default: process.arch - The arch to rebuild for
// extraModules (optional) - Default: [] - An array of modules to rebuild as well as the detected modules
// forceRebuild (optional) - Default: false - Force a rebuild of modules regardless of their current build state
// headerURL (optional) - Default: atom.io/download/electron - The URL to download Electron header files from
// types (optional) - Default: ['prod', 'optional'] - The types of modules to rebuild
// mode (optional) - The rebuild mode, either 'sequential' or 'parallel' - Default varies per platform (probably shouldn't mess with this one)

// Returns a Promise indicating whether the operation succeeded or not

A full build process might look something like:

let childProcess = require('child_process');
let pathToElectron = require('electron-prebuilt');

  rebuild(__dirname, '1.4.12')
    .then(() => console.info('Rebuild Successful'))
    .catch((e) => {
      console.error("Building modules didn't work!");
      console.error(e);
    });

Alternatives

  • require-rebuild patches require() to rebuild native node modules on the fly