1 | initial version |
To include process.env while utilizing Vite, follow these steps:
.env
file at the root of your project directory..env
file in the format NAME=VALUE
, for example:VITE_API_KEY=123456789
VITE_BASE_URL=https://example.com
vite.config.js
), import the dotenv
package:import dotenv from 'dotenv'
config
method of the dotenv
package to load the environment variables:dotenv.config()
process.env
object:export default {
// other Vite config options
plugins: [],
define: {
'process.env': process.env
}
}
process.env.VITE_API_KEY
and process.env.VITE_BASE_URL
.