Skip to content

access .env values in vite.config.js file? #2260

Answered by Matt-Deacalion
JeffBeltran asked this question in Q&A
Discussion options

You must be logged in to vote

You could load the app level env variables and add them to the Node level env variables (credit: Alec Larson):

import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';


export default ({ mode }) => {
    process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };

    // import.meta.env.YinYang -> process.env.YinYang

    return defineConfig({
        plugins: [vue()],
    });
}

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@ngekoding
Comment options

@awacode21
Comment options

@Shinigami92
Comment options

@awacode21
Comment options

@MatheusRoichman
Comment options

Answer selected by JeffBeltran
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants