Merge pull request #39 from ianstormtaylor/patch-1

perf: use `require.resolve` to find electron package
This commit is contained in:
alex.wei 2022-10-23 01:39:20 +08:00 committed by GitHub
commit a62b20359b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -511,8 +511,8 @@ export function externalizeDepsPlugin(options: ExternalOptions = {}): Plugin | n
function getElectronMainVer(root: string): string {
let mainVer = process.env.ELECTRON_MAIN_VER || ''
if (!mainVer) {
const electronModulePath = path.resolve(root, 'node_modules', 'electron')
const pkg = path.join(electronModulePath, 'package.json')
const electronModulePath = require.resolve('electron')
const pkg = path.join(electronModulePath, '../package.json')
if (fs.existsSync(pkg)) {
const require = createRequire(import.meta.url)
const version = require(pkg).version