diff --git a/docs/Options.md b/docs/Options.md
index 3cbfcf438dd..899d787f77e 100644
--- a/docs/Options.md
+++ b/docs/Options.md
@@ -81,6 +81,7 @@ Don't customize paths to background and icon, — just follow conventions.
| compression | The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
| afterPack | *programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned.
| npmRebuild | *two package.json structure only* Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
+| npmSkipBuildFromSource | *two package.json structure only* Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`.
| nodeGypRebuild | Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
| electronDist | The path to custom Electron build (e.g. `~/electron/out/R`). Only macOS supported, file issue if need for Linux or Windows.
diff --git a/src/metadata.ts b/src/metadata.ts
index 69a565f4bf2..8b85bc63f16 100755
--- a/src/metadata.ts
+++ b/src/metadata.ts
@@ -201,6 +201,11 @@ export interface BuildMetadata {
*/
readonly npmRebuild?: boolean
+ /*
+ *two package.json structure only* Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`.
+ */
+ readonly npmSkipBuildFromSource?: boolean
+
/*
Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
*/
diff --git a/src/packager.ts b/src/packager.ts
index ed4829f722e..76b6190e5f8 100644
--- a/src/packager.ts
+++ b/src/packager.ts
@@ -235,7 +235,8 @@ export class Packager implements BuildInfo {
log("Skip app dependencies rebuild because npmRebuild is set to false")
}
else if (platform.nodeName === process.platform) {
- await installDependencies(this.appDir, this.electronVersion, Arch[arch], (await statOrNull(path.join(this.appDir, "node_modules"))) == null ? "install" : "rebuild")
+ let doSourceBuild = !(this.devMetadata.build.npmSkipBuildFromSource === true)
+ await installDependencies(this.appDir, this.electronVersion, Arch[arch], (await statOrNull(path.join(this.appDir, "node_modules"))) == null ? "install" : "rebuild", doSourceBuild)
}
else {
log("Skip app dependencies rebuild because platform is different")
diff --git a/src/util/util.ts b/src/util/util.ts
index b02bd7694bb..52979edc361 100644
--- a/src/util/util.ts
+++ b/src/util/util.ts
@@ -16,8 +16,8 @@ export const debug7z = debugFactory("electron-builder:7z")
const DEFAULT_APP_DIR_NAMES = ["app", "www"]
-export function installDependencies(appDir: string, electronVersion: string, arch: string = process.arch, command: string = "install"): BluebirdPromise {
- return task(`${(command === "install" ? "Installing" : "Rebuilding")} app dependencies for arch ${arch} to ${appDir}`, spawnNpmProduction(command, appDir, getGypEnv(electronVersion, arch)))
+export function installDependencies(appDir: string, electronVersion: string, arch: string = process.arch, command: string = "install", fromSource: boolean = true): BluebirdPromise {
+ return task(`${(command === "install" ? "Installing" : "Rebuilding")} app dependencies for arch ${arch} to ${appDir}`, spawnNpmProduction(command, appDir, getGypEnv(electronVersion, arch), fromSource))
}
export function getGypEnv(electronVersion: string, arch: string): any {
@@ -32,9 +32,9 @@ export function getGypEnv(electronVersion: string, arch: string): any {
})
}
-export function spawnNpmProduction(command: string, appDir: string, env?: any): BluebirdPromise {
+export function spawnNpmProduction(command: string, appDir: string, env?: any, forceBuild: boolean = true): BluebirdPromise {
let npmExecPath = process.env.npm_execpath || process.env.NPM_CLI_JS
- const npmExecArgs = [command, "--production", "--build-from-source", "--cache-min", "999999999"]
+ let npmExecArgs = [command, "--production", "--cache-min", "999999999"]
if (npmExecPath == null) {
npmExecPath = process.platform === "win32" ? "npm.cmd" : "npm"
}
@@ -42,6 +42,9 @@ export function spawnNpmProduction(command: string, appDir: string, env?: any):
npmExecArgs.unshift(npmExecPath)
npmExecPath = process.env.npm_node_execpath || process.env.NODE_EXE || "node"
}
+ if (forceBuild) {
+ npmExecArgs.push("--build-from-source")
+ }
return spawn(npmExecPath, npmExecArgs, {
cwd: appDir,