Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for passing arguments to electron in dev and preview modes. #339

Merged
merged 3 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ cli
process.env.NO_SANDBOX = '1'
}

if (options['--']) {
process.env.ELECTRON_CLI_ARGS = JSON.stringify(options['--']);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, when I run yarn build on this branch, prettier wants these semicolons removed

% yarn build      
yarn run v1.22.19
$ npm run lint && node scripts/build.js

> electron-vite@1.0.29 lint
> eslint --ext .ts src/**


/Users/pzich/Projects/config/razorcrest/ui/node_modules/electron-vite/src/cli.ts
  100:68  error  Delete `;`  prettier/prettier
  158:68  error  Delete `;`  prettier/prettier

✖ 2 problems (2 errors, 0 warnings)
  2 errors and 0 warnings potentially fixable with the `--fix` option.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pzcfg Thanks for your review, I got it.

}

if (options.entry) {
process.env.ELECTRON_ENTRY = options.entry
}
Expand Down Expand Up @@ -150,6 +154,10 @@ cli
process.env.ELECTRON_ENTRY = options.entry
}

if (options['--']) {
process.env.ELECTRON_CLI_ARGS = JSON.stringify(options['--']);
}

try {
await preview(inlineConfig, { skipBuild: options.skipBuild })
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function startElectron(root: string | undefined): ChildProcess {

const isDev = process.env.NODE_ENV_ELECTRON_VITE === 'development'

const args: string[] = []
const args: string[] = process.env.ELECTRON_CLI_ARGS ? JSON.parse(process.env.ELECTRON_CLI_ARGS) : []

if (!!process.env.REMOTE_DEBUGGING_PORT && isDev) {
args.push(`--remote-debugging-port=${process.env.REMOTE_DEBUGGING_PORT}`)
Expand Down