Skip to content
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

vite.config中获取环境变量 #83

Open
any86 opened this issue Feb 8, 2022 · 0 comments
Open

vite.config中获取环境变量 #83

any86 opened this issue Feb 8, 2022 · 0 comments

Comments

@any86
Copy link
Owner

any86 commented Feb 8, 2022

把参数改成函数就可以获取到当前的"mode".

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig(({mode}) => {
  return {
    publicDir:'production' === mode ? './' : '/',
    plugins: [vue()]
  }
})

通过"loadEnv "还可以获取到.env文件中的信息

import { loadEnv } from 'vite'
loadEnv(mode,process.cwd());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant