diff --git a/beforeBuild.js b/beforeBuild.js index c08296a9..d63b3609 100644 --- a/beforeBuild.js +++ b/beforeBuild.js @@ -1,17 +1,26 @@ 'use strict' -const cp = require('child_process') +const cp = require('child_process'); +const rimraf = require('rimraf'); +const process = require('process'); // Rebuild native modules for ia32 and run webpack again for the ia32 part of windows packages exports.default = function(context) { if (context.platform.name === 'windows') { cp.execFileSync( 'bash', - ['./node_modules/.bin/electron-rebuild', '--types', 'dev', '--arch', context.arch] + ['./node_modules/.bin/electron-rebuild', '--types', 'dev', '--arch', context.arch], ); + rimraf.sync('generated'); cp.execFileSync( 'bash', - ['./node_modules/.bin/webpack'] + ['./node_modules/.bin/webpack'], + { + env: { + ...process.env, + npm_config_target_arch: context.arch, + }, + }, ); } } diff --git a/webpack.config.ts b/webpack.config.ts index 67561937..3168b0c7 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -22,6 +22,7 @@ import * as MiniCssExtractPlugin from 'mini-css-extract-plugin'; import * as os from 'os'; import outdent from 'outdent'; import * as path from 'path'; +import { env } from 'process'; import * as SimpleProgressWebpackPlugin from 'simple-progress-webpack-plugin'; import * as TerserPlugin from 'terser-webpack-plugin'; import { BannerPlugin, NormalModuleReplacementPlugin } from 'webpack'; @@ -77,7 +78,11 @@ function renameNodeModules(resourcePath: string) { function findLzmaNativeBindingsFolder(): string { const files = readdirSync(path.join('node_modules', 'lzma-native')); - const bindingsFolder = files.find((f) => f.startsWith('binding-')); + const bindingsFolder = files.find( + (f) => + f.startsWith('binding-') && + f.endsWith(env.npm_config_target_arch || os.arch()), + ); if (bindingsFolder === undefined) { throw new Error('Could not find lzma_native binding'); }