dcloudio / uni-preset-vue

uni-app preset for vue
Apache License 2.0
300 stars 116 forks source link

使用vue3/vite版,如何在编译时指定特殊环境,例如想让process.env.NODE_ENV=test #83

Closed seepine closed 1 year ago

seepine commented 1 year ago

尝试使用cross-env配置但无效,是因为uni build命令默认为prod了吗

cross-env NODE_ENV=test UNI_OUTPUT_DIR=dist/build/mp-weixin-test uni build -p mp-weixin
476421978 commented 1 year ago

尝试使用cross-env配置但无效,是因为uni build命令默认为prod了吗

cross-env NODE_ENV=test UNI_OUTPUT_DIR=dist/build/mp-weixin-test uni build -p mp-weixin

看这里改用vite配置文件:https://github.com/dcloudio/uni-preset-vue/issues/35#issuecomment-994258623

seepine commented 1 year ago

尝试使用cross-env配置但无效,是因为uni build命令默认为prod了吗

cross-env NODE_ENV=test UNI_OUTPUT_DIR=dist/build/mp-weixin-test uni build -p mp-weixin

看这里改用vite配置文件:#35 (comment)

正确的,重新尝试了一下,pnpm build:mp-weixin -m test,通过 import.meta.env.MODE 能够取到 test,因此不通过 process.env.NODE_ENV 判断而通过 import.meta.env.MODE 即可

import.meta.env.MODE 的值和 NODE_ENV 一致在开发环境为 development,在build时为 production,若想自定义时,通过pnpm build:xxx -m test 即可自定义模式值