该可执行文件将根据您的Electron项目使用的Node.js版本重建原生Node.js模块(native Node.js modules)。这使您可以在Electron应用程序中使用本机Node.js模块,而无需完全匹配您的系统版本的Node.js(通常不是这种情况,有时甚至是不可能的)。
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
Node v10.12.0 or higher is required. Building the native modules from source uses node-gyp
, refer to the link for its installation/runtime requirements.
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. Modules will only be rebuilt if they
also match the types of dependencies being rebuilt
(see --types).
-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
separated 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
-o, --only Only build specified module, or comma separated
list of modules. All others are ignored.
-b, --debug Build debug version of modules
--prebuild-tag-prefix GitHub tag prefix passed to prebuild-install.
Default is "v"
Copyright 2016