Question: How to use modes and environment variables in vite.config.js ?
See original GitHub issueI try to use env variables in vite.config.js like this:
const isDev1 = import.meta.env.MODE === 'development'
const isDev2 = process.env.MODE === 'development'
const dev_port1 = import.meta.env.VUE_DEVPORT
const dev_port2 = process.env.VUE_DEVPORT
module.exports = {
base: './',
port: dev_port1,
sourcemap: isDev1,
optimizeDeps: {
include: ['axios']
}
}
Environment variables cannot be accessed either way,
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Env Variables and Modes - Vite
Vite exposes env variables on the special import.meta.env object. ... An env file for a specific mode (e.g. .env.production ) will take higher...
Read more >How can I use Vite env variables in vite.config.js?
You can load the app level env variables and add them to the Node level env variables: import { defineConfig, loadEnv } from...
Read more >How to use a .env file with Vite and Vue? - Samanja Cartagena
env file can be used by using env.variable in the config file except in the config file load env needs to be imported...
Read more >Environment Variables and Modes in Vite - Vue School
In this lesson, we learn about the value of environment variables, how to define them with .env files, and how to access them...
Read more >Handling process.env - Quasar Framework
`.env` file // If you want .env file to override the terminal variables, // use `require('dotenv').config({ override: true })` instead return ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@hyingreborn you are right about
NODE_ENV
. It’s not set yet invite.config.js
. I don’t know if it intentional by design but you could create your own scripts in yourpackage.json
:In your
vite.config.js
, now you can manipulate it:https://vitejs.dev/config/#conditional-config
P.S this issue is way out of date.