# tsconfig.json

{
  "compilerOptions": {
    "types": ["vite/client"],
    ...
  },
 "include: [
   "src/**/*.ts" 
 ] }

 记得把新加的文件加入include配置中

 

读取环境变量文件.env Files

Vite使用dotenv从你的项目根目录下的以下文件中加载额外的环境变量:

.env.[mode]         # only loaded in specified mode

 

为了防止意外地将env变量泄漏到客户端,只有以VITE_前缀的变量才会暴露给经过VITE_处理的代码。例如:

# .env.production
# 读取 console.log(import.meta.env.VITE_API_URL);
# 读取 console.log(import.meta.env.MAP_KEY);
MAP_KEY = xxxxxxxxxxxxxxx
VITE_API_URL = http://prod.api.com

 只有VITE_API_URL会暴露为import.meta.env。您的客户端源代码的VITE_API_URL,但MAP_KEY不会。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2021-05-27
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-08-11
  • 2021-09-09
  • 2021-07-22
相关资源
相似解决方案