ttk-cli / uni-vue3-vite-ts-pinia

A template for uniapp with vue3.
MIT License
353 stars 102 forks source link

config/env.ts问价中获取环境变量和uni无法编译。 #59

Open layzf opened 3 months ago

layzf commented 3 months ago

遇到一个奇怪的问题: 1.在src/config/env.ts中使用import.meta.env.MODE无法正常编译,其他文件可以使用。 2.在src/config/env.ts中使用uni的API无法正常编译(uni is not defined),其他文件可以使用。

Allen-1998 commented 3 months ago

如果没有开发h5端的需求的话,可以把 https://github.com/ttk-cli/uni-vue3-vite-ts-pinia/blob/f0d960b2d590a7f3af3503c7ce35796e88b3d623/vite.config.ts#L10https://github.com/ttk-cli/uni-vue3-vite-ts-pinia/blob/f0d960b2d590a7f3af3503c7ce35796e88b3d623/vite.config.ts#L44-L56 去掉

Allen-1998 commented 3 months ago

在 vite.config.ts 中导入env文件是为了设置 h5 开发环境的代理(小程序和app不需要设置),因为 import.meta.env.MODE 和 uni 在编译阶段是不存在的,所以在这个文件中使用会报错