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

Conversation

mifi
Copy link
Contributor

@mifi mifi commented Nov 25, 2023

thanks for this great module! I just started using it and it works great. there's one thing I was missing:

Description

Add support for passing arguments to electron in dev and preview modes.

fixes #149

this allows us to pass custom args to the electron process that can be read directly inside electron on process.argv, like so:

yarn dev -- --my-custom-arg some-value
yarn start -- --my-custom-arg some-value

(assuming my package.json is like this:)

    "start": "electron-vite preview",
    "dev": "electron-vite dev -w",

This is beneficial because it reduces the gap between production and development, decreasing the chance of making mistakes due to differences in the two (three) environments. and it's pretty standard for something that runs something else that -- will pass along arguments to what it runs

Additional context

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

@mifi mifi mentioned this pull request Nov 25, 2023
4 tasks
@matthme
Copy link

matthme commented Dec 8, 2023

Oh that's fabulous. I have been looking for this as well, can't wait for it to get merged!

@pzcfg
Copy link

pzcfg commented Dec 15, 2023

Amazing 🙏 Please let's get this merged. The recommended solution of building an entirely different codepath for dev vs production seems like a lot of extra work and very error prone.

@@ -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.

@alex8088
Copy link
Owner

@mifi

Thank you for your contribution. It's too late to respond.

This is great and really useful, I didn't notice that cac has this feature. But it still needs some testing, including user args support and the impact on debugging. If there are no problems, it may be added to version 2.0

@alex8088 alex8088 merged commit 9b04362 into alex8088:master Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pass CLI parameters to electron
4 participants