-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Question: How to use modes and environment variables in vite.config.js ? #512
Comments
|
The previous code example was misspelled, now the console still print error :
|
The current scan env file need ensure |
@hyingreborn you can't use Your
If you want to check your environment (or mode) you can access Once the vars are loaded, you could use the |
@Aferz Thanks a lot for your explanation ! I've tried using process.env to get the environment variable, but it haven't NODE_ENV,there is also no variable prefixed by VITE_ 。 |
@hyingreborn you are right about "scripts": {
"build:dev": "APP_ENV=development vite build",
"build:prod": "APP_ENV=production vite build",
} In your const mode = process.env.APP_ENV // This now exists.
module.exports = {
mode: mode, // This will set the mode, to avoid confusions.
} |
@Aferz Thanks a lot! Maybe someday Vite will be the same as VueCLI... |
Well, it already has almost 100% feature parity (when things make sense). In Vue CLI you can't access you env vars in your vue.config.js either, for the same reason than vite. Glad it helped. Cheers. |
Mode and env variables are an "app level" concept - they are only usable inside your app source code, not the config file. |
Hi, |
maybe it is helpful
|
https://vitejs.dev/config/#conditional-config P.S this issue is way out of date. |
I try to use env variables in vite.config.js like this:
Environment variables cannot be accessed either way,
The text was updated successfully, but these errors were encountered: