Home > Net >  How to change envPrefix in vite react?
How to change envPrefix in vite react?

Time:10-15

I created a simple react app using npm init vite Appname -- --template react command.
And in .env file, variables have to have VITE_ prefix, and don't look good.
I checked this guide, but don't know how to change the envPrefix. Can someone tell me how to change envDir and envPrefix?

Thank you in advance for many help.

This is my vite.config.js file.

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()]
})

CodePudding user response:

Try updating the file to include the properties that you shared the docs for:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  envPrefix: 'CH_',
  envDir: './environment'
})
  • Related