yue1123 / vite-plugin-env-parse

Parse env string values to correct values, not all values are strings. And automatically generate ImportMetaEnv
MIT License
73 stars 4 forks source link

.env.test这类命名文件中的环境变量都没读取到 #2

Closed liub1934 closed 5 months ago

liub1934 commented 5 months ago

Describe the bug .env.test这类命名文件中的环境变量都没读取到。

To Reproduce Steps to reproduce the behavior:

  1. 新建一个.env.test文件
  2. 内容写入VITE_BUILD_ENV = test
  3. 最终生成的env.d.ts中没有VITE_BUILD_ENV

Node:v16.15.0 Vite:4.5.2

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

yue1123 commented 5 months ago

你在启动命令加了vite --mode test没

liub1934 commented 5 months ago

你在启动命令加了vite --mode test没

dev启动没有加mode,打包的时候会带mode

"scripts": {
    "dev": "run-p type-check && vite",
    "build-test": "run-p type-check && vite build --mode test",
    "build-prod": "run-p type-check && vite build --mode prod",
    "build-stag": "run-p type-check && vite build --mode stag",
    "build-dr": "run-p type-check && vite build --mode dr",
    "report": "run-p type-check && vite build --mode test -- --report",
    "compress-svg": "npx ts-node compress-svg.ts",
    "preview": "vite preview",
    "type-check": "vue-tsc --build --force",
    "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore --ignore-path .eslintignore",
    "format": "prettier --write src/"
  },
yue1123 commented 5 months ago

dev 也需要加,不加的话 vite 是读取不到的,这个插件是不管读取的,只会对 vite 读取到的环境变量做转换。

不加--mode,默认值就是 development,这种情况下vite 只会读取.env.env.developmentenv.localenv.development.local.env.test 没在其中,自然不会有。

可以阅读哈 vite 文档,有很详细的说明。