diff --git a/src/cli.ts b/src/cli.ts
index 1a69c29..209f0b2 100644
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -24,6 +24,7 @@ interface GlobalCLIOptions {
w?: boolean
watch?: boolean
outDir?: string
+ entry?: string
}
interface DevCLIOptions {
@@ -59,6 +60,7 @@ cli
.option('--ignoreConfigWarning', `[boolean] ignore config warning`)
.option('--sourcemap', `[boolean] output source maps for debug (default: false)`)
.option('--outDir
', `[string] output directory (default: out)`)
+ .option('--entry ', `[string] specify electron entry file`)
// dev
cli
@@ -83,6 +85,10 @@ cli
process.env.V8_INSPECTOR_BRK_PORT = typeof options.inspectBrk === 'number' ? `${options.inspectBrk}` : '5858'
}
+ if (options.entry) {
+ process.env.ELECTRON_ENTRY = options.entry
+ }
+
const { createServer } = await import('./server')
const inlineConfig = createInlineConfig(root, options)
@@ -103,6 +109,10 @@ cli.command('build [root]', 'build for production').action(async (root: string,
const { build } = await import('./build')
const inlineConfig = createInlineConfig(root, options)
+ if (options.entry) {
+ process.env.ELECTRON_ENTRY = options.entry
+ }
+
try {
await build(inlineConfig)
} catch (e) {
@@ -120,6 +130,10 @@ cli
const { preview } = await import('./preview')
const inlineConfig = createInlineConfig(root, options)
+ if (options.entry) {
+ process.env.ELECTRON_ENTRY = options.entry
+ }
+
try {
await preview(inlineConfig, { skipBuild: options.skipBuild })
} catch (e) {
diff --git a/src/electron.ts b/src/electron.ts
index 6ce18b1..b2add49 100644
--- a/src/electron.ts
+++ b/src/electron.ts
@@ -6,6 +6,7 @@ import { type ChildProcess, spawn } from 'node:child_process'
const _require = createRequire(import.meta.url)
const ensureElectronEntryFile = (root = process.cwd()): void => {
+ if (process.env.ELECTRON_ENTRY) return
const pkg = path.join(root, 'package.json')
if (fs.existsSync(pkg)) {
const main = require(pkg).main
@@ -133,7 +134,9 @@ export function startElectron(root: string | undefined): ChildProcess {
args.push(`--inspect-brk=${process.env.V8_INSPECTOR_BRK_PORT}`)
}
- const ps = spawn(electronPath, ['.'].concat(args), { stdio: 'inherit' })
+ const entry = process.env.ELECTRON_ENTRY || '.'
+
+ const ps = spawn(electronPath, [entry].concat(args), { stdio: 'inherit' })
ps.on('close', process.exit)
return ps