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

Allow setting mode via environment variable #17513

Open
4 tasks done
rschamp opened this issue Jun 18, 2024 · 2 comments
Open
4 tasks done

Allow setting mode via environment variable #17513

rschamp opened this issue Jun 18, 2024 · 2 comments

Comments

@rschamp
Copy link

rschamp commented Jun 18, 2024

Description

I am used to being able to configure my builds in CI via environment variables. E.g., if I have npm run build I would like to be able to use that same command, but have it behave differently based on the environment. Currently I can somewhat affect my build via NODE_ENV=production for a production build and NODE_ENV=development for a staging build. I would like to have the same control for the mode.

Suggested solution

Similarly to NODE_ENV we could have the VITE_MODE or MODE environment variable change the mode.

Alternative

In order to change import.meta.env.MODE, I need a separate command npm run build:staging, or I need to adjust the command I run like npm run build -- --mode staging. These workarounds make my CI config more complex than it could be.

Additional context

No response

Validations

@sapphi-red
Copy link
Member

If you can put "build": "vite --mode ${VITE_MODE:-production}" (for bash), then I think you can run npm run build/MODE=staging npm run build.

@rgrace-puck
Copy link

If you need to do this in a cross-platform way (e.g. for developer machines and CI builds), I used the package cross-replace to get the environment variable value.

Install:
npm install --save-dev cross-replace

package.json

"build": "cross-replace vite build --mode %VITE_MODE%"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants