Skip to content

Commit 0116386

Browse files
committed
feat(cli): supports specifying electron entry file (#270)
1 parent 8b83987 commit 0116386

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/cli.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface GlobalCLIOptions {
2424
w?: boolean
2525
watch?: boolean
2626
outDir?: string
27+
entry?: string
2728
}
2829

2930
interface DevCLIOptions {
@@ -59,6 +60,7 @@ cli
5960
.option('--ignoreConfigWarning', `[boolean] ignore config warning`)
6061
.option('--sourcemap', `[boolean] output source maps for debug (default: false)`)
6162
.option('--outDir <dir>', `[string] output directory (default: out)`)
63+
.option('--entry <file>', `[string] specify electron entry file`)
6264

6365
// dev
6466
cli
@@ -83,6 +85,10 @@ cli
8385
process.env.V8_INSPECTOR_BRK_PORT = typeof options.inspectBrk === 'number' ? `${options.inspectBrk}` : '5858'
8486
}
8587

88+
if (options.entry) {
89+
process.env.ELECTRON_ENTRY = options.entry
90+
}
91+
8692
const { createServer } = await import('./server')
8793
const inlineConfig = createInlineConfig(root, options)
8894

@@ -103,6 +109,10 @@ cli.command('build [root]', 'build for production').action(async (root: string,
103109
const { build } = await import('./build')
104110
const inlineConfig = createInlineConfig(root, options)
105111

112+
if (options.entry) {
113+
process.env.ELECTRON_ENTRY = options.entry
114+
}
115+
106116
try {
107117
await build(inlineConfig)
108118
} catch (e) {
@@ -120,6 +130,10 @@ cli
120130
const { preview } = await import('./preview')
121131
const inlineConfig = createInlineConfig(root, options)
122132

133+
if (options.entry) {
134+
process.env.ELECTRON_ENTRY = options.entry
135+
}
136+
123137
try {
124138
await preview(inlineConfig, { skipBuild: options.skipBuild })
125139
} catch (e) {

src/electron.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { type ChildProcess, spawn } from 'node:child_process'
66
const _require = createRequire(import.meta.url)
77

88
const ensureElectronEntryFile = (root = process.cwd()): void => {
9+
if (process.env.ELECTRON_ENTRY) return
910
const pkg = path.join(root, 'package.json')
1011
if (fs.existsSync(pkg)) {
1112
const main = require(pkg).main
@@ -133,7 +134,9 @@ export function startElectron(root: string | undefined): ChildProcess {
133134
args.push(`--inspect-brk=${process.env.V8_INSPECTOR_BRK_PORT}`)
134135
}
135136

136-
const ps = spawn(electronPath, ['.'].concat(args), { stdio: 'inherit' })
137+
const entry = process.env.ELECTRON_ENTRY || '.'
138+
139+
const ps = spawn(electronPath, [entry].concat(args), { stdio: 'inherit' })
137140
ps.on('close', process.exit)
138141

139142
return ps

0 commit comments

Comments
 (0)