fix(bytecodePlugin): not work in monorepo (#128)
This commit is contained in:
parent
05e0cc6db1
commit
f7f19f9649
|
@ -1,6 +1,7 @@
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
import { spawn } from 'node:child_process'
|
import { spawn } from 'node:child_process'
|
||||||
|
import { createRequire } from 'node:module'
|
||||||
import colors from 'picocolors'
|
import colors from 'picocolors'
|
||||||
import { type Plugin, type ResolvedConfig, normalizePath, createFilter } from 'vite'
|
import { type Plugin, type ResolvedConfig, normalizePath, createFilter } from 'vite'
|
||||||
import * as babel from '@babel/core'
|
import * as babel from '@babel/core'
|
||||||
|
@ -10,8 +11,10 @@ import { getElectronPath } from '../electron'
|
||||||
|
|
||||||
// Inspired by https://github.com/bytenode/bytenode
|
// Inspired by https://github.com/bytenode/bytenode
|
||||||
|
|
||||||
|
const _require = createRequire(import.meta.url)
|
||||||
|
|
||||||
function getBytecodeCompilerPath(): string {
|
function getBytecodeCompilerPath(): string {
|
||||||
return path.resolve(process.cwd(), 'node_modules', 'electron-vite', 'bin', 'electron-bytecode.js')
|
return path.join(path.dirname(_require.resolve('electron-vite/package.json')), 'bin', 'electron-bytecode.js')
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileToBytecode(code: string): Promise<Buffer> {
|
function compileToBytecode(code: string): Promise<Buffer> {
|
||||||
|
|
Loading…
Reference in a new issue