在我的Vite项目中使用以下.env:
# To prevent accidentally leaking env variables to the client, only
# variables prefixed with VITE_ are exposed to your Vite-processed code
VITE_NAME=Wheatgrass
VITE_PORT=8080如何在我的vite.config.js中使用VITE_PORT
发布于 2021-02-27 00:01:21
您可以加载app level环境变量并将它们添加到Node level环境变量中:
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.VITE_NAME available here with: process.env.VITE_NAME
// import.meta.env.VITE_PORT available here with: process.env.VITE_PORT
return defineConfig({
plugins: [vue()],
server: {
port: process.env.VITE_PORT,
},
});
}https://stackoverflow.com/questions/66389043
复制相似问题